From patchwork Wed Dec 12 00:03:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 10725329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4F266C5 for ; Wed, 12 Dec 2018 00:12:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A452D2B550 for ; Wed, 12 Dec 2018 00:12:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98A382B583; Wed, 12 Dec 2018 00:12:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C83162B550 for ; Wed, 12 Dec 2018 00:12:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1924C8E00E7; Tue, 11 Dec 2018 19:12:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 08A438E00E4; Tue, 11 Dec 2018 19:12:11 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC0CC8E00E7; Tue, 11 Dec 2018 19:12:11 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 6D1B38E00C9 for ; Tue, 11 Dec 2018 19:12:11 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id v72so10975839pgb.10 for ; Tue, 11 Dec 2018 16:12:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Hp1GEthNazPZ/TRqQgCHn0d9BdgUz5hb+WmE6z4c0IY=; b=g1VhVKp7HVQR+HN8+7/XlS1cgqAu2DmkPgwqY/HGX018SSr2GyDg/FDlu6vsFm1C1i D256nfXsbKN9NO3/km1Ttwegc3hxUO78VslmHHiWKwiMA6gW9EhOkYaQAIhltrzTjpJn YQvIpqGCh0plBgohA9jjXiDgolmNZsIU4pftvlyF3vjOLgwj0jx7ghI31OlQgSro/zdR Qc9nTUROhR8wJ6MQdu0WeMp8RdFQc7b6SJ4ladYaatSCsZu3K+mUcslts557fBR2q3Ou KR/aer8/ENehOs4OueLHrLbruOLqvn4RPshxbqUnlv4gleQGjXkGKFCasGTR7SvnmKOJ P62g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AA+aEWbzDcYBg68Qjd7oDjRJZY3/ftUQZv817DLrH6fMpLSx9kVND/+X kUXgHbD9umVYD0XNTPTyBfPX9Ai5hPdgFE+pOK95KZLwj46BQYweobwnYqLv8IcTFj0a82R23qQ 5yRYzY40uwImTigXHX1FvzYmxbZswsvO/2jsiN+z4ZEjlSAx91anJpqOhXSZmzvb04A== X-Received: by 2002:a63:5a57:: with SMTP id k23mr16361205pgm.5.1544573530946; Tue, 11 Dec 2018 16:12:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/VqHCmy7SlZGZvQ3Q0tAV3t5rzst3t+fD9bxSglCwlqfjHhXtPiEsC7xV4XxoepUmsq7uoo X-Received: by 2002:a63:5a57:: with SMTP id k23mr16361175pgm.5.1544573530123; Tue, 11 Dec 2018 16:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544573530; cv=none; d=google.com; s=arc-20160816; b=Ot9X5Hir9W6dZuGqMNuxF/KLqNWF/okCj1jv0j8zf4ebsPRdLC4Wn/2Huf7le/MNuI 0v0yMPJOHGGWATOBbgQt1YePAEG4OAxpk3qWka07Bc7gXWYAbE6ojktWmC6/imUcVhAc L0WM+7Js9In+Cso7tzhNTc651pIV/Tm6vhKJwH07FFsVeA45Dy/cvxX/niNaWQoGakgp DKIWFzYjwy9xV3wWGDeuWVkiJ6Eu+R0qfCg7opgSKGXoNwE9xnVJ4ktxJ7YVSR3p5y0d Gpgw/8T7YbAjKbW7tVcpZFDRIITvgNonaNVDKyymRVDi84EvXmaYDBqtpGBK9O5KuSON Lv7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Hp1GEthNazPZ/TRqQgCHn0d9BdgUz5hb+WmE6z4c0IY=; b=lN6J9+fGTqLOE3sSYyt0qPxJL5OBu+oyiH7lh40rDTSi5tWA3TwbFFp+zSPre4ZVcA TjRaTnQOzGdZMhwgE/N3J7qHDZnIK5WxWSMrqSKM8ybTnaCaxg2OR5o+6u/ApnwwAbaN d7yd5xyC0g0GkMIzJI9wFEMHJro+vXeqJXsren4ZvjdR43Qwp4B7/4BrBKj/NFYryIdc p9C0zPWccZwLTtvE3k0wWqbbdh6SE7HBu8D5qGYDHaBbSKcZj5UeXIVglte58Z/wFZju 5fR+XKXUPU5ZC7gIQ7JLngyqfSB5R7251pgrEeyc02W/HjNkJsisWgr4PPFbYiPemM/w SZBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id f18si13139318pgl.457.2018.12.11.16.12.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 16:12:10 -0800 (PST) Received-SPF: pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.31 as permitted sender) client-ip=134.134.136.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 16:12:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="282839406" Received: from rpedgeco-desk5.jf.intel.com ([10.54.75.141]) by orsmga005.jf.intel.com with ESMTP; 11 Dec 2018 16:12:07 -0800 From: Rick Edgecombe To: akpm@linux-foundation.org, luto@kernel.org, will.deacon@arm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, naveen.n.rao@linux.vnet.ibm.com, anil.s.keshavamurthy@intel.com, davem@davemloft.net, mhiramat@kernel.org, rostedt@goodmis.org, mingo@redhat.com, ast@kernel.org, daniel@iogearbox.net, jeyu@kernel.org, namit@vmware.com, netdev@vger.kernel.org, ard.biesheuvel@linaro.org, jannh@google.com Cc: kristen@linux.intel.com, dave.hansen@intel.com, deneen.t.dock@intel.com, Rick Edgecombe Subject: [PATCH v2 3/4] bpf: switch to new vmalloc vfree flags Date: Tue, 11 Dec 2018 16:03:53 -0800 Message-Id: <20181212000354.31955-4-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181212000354.31955-1-rick.p.edgecombe@intel.com> References: <20181212000354.31955-1-rick.p.edgecombe@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This switches to use the new vmalloc flags to control freeing memory with special permissions. Signed-off-by: Rick Edgecombe --- include/linux/filter.h | 26 ++++++++++++-------------- kernel/bpf/core.c | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index 795ff0b869bb..2aeb93d3337d 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -487,7 +488,6 @@ struct bpf_prog { u16 pages; /* Number of allocated pages */ u16 jited:1, /* Is our filter JIT'ed? */ jit_requested:1,/* archs need to JIT the prog */ - undo_set_mem:1, /* Passed set_memory_ro() checkpoint */ gpl_compatible:1, /* Is filter GPL compatible? */ cb_access:1, /* Is control block accessed? */ dst_needed:1, /* Do we need dst entry? */ @@ -699,24 +699,23 @@ bpf_ctx_narrow_access_ok(u32 off, u32 size, u32 size_default) static inline void bpf_prog_lock_ro(struct bpf_prog *fp) { - fp->undo_set_mem = 1; - set_memory_ro((unsigned long)fp, fp->pages); -} + struct vm_struct *vm = find_vm_area(fp); -static inline void bpf_prog_unlock_ro(struct bpf_prog *fp) -{ - if (fp->undo_set_mem) - set_memory_rw((unsigned long)fp, fp->pages); + if (vm) + vm->flags |= VM_HAS_SPECIAL_PERMS; + set_memory_ro((unsigned long)fp, fp->pages); } static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr) { - set_memory_ro((unsigned long)hdr, hdr->pages); -} + struct vm_struct *vm = find_vm_area(hdr); -static inline void bpf_jit_binary_unlock_ro(struct bpf_binary_header *hdr) -{ - set_memory_rw((unsigned long)hdr, hdr->pages); + if (vm) { + vm->flags |= VM_HAS_SPECIAL_PERMS; + vm->flags |= VM_IMMEDIATE_UNMAP; + } + + set_memory_ro((unsigned long)hdr, hdr->pages); } static inline struct bpf_binary_header * @@ -746,7 +745,6 @@ void __bpf_prog_free(struct bpf_prog *fp); static inline void bpf_prog_unlock_free(struct bpf_prog *fp) { - bpf_prog_unlock_ro(fp); __bpf_prog_free(fp); } diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index b1a3545d0ec8..bd3efd7ce526 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -663,7 +663,6 @@ void __weak bpf_jit_free(struct bpf_prog *fp) if (fp->jited) { struct bpf_binary_header *hdr = bpf_jit_binary_hdr(fp); - bpf_jit_binary_unlock_ro(hdr); bpf_jit_binary_free(hdr); WARN_ON_ONCE(!bpf_prog_kallsyms_verify_off(fp));