Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp770909ybl; Thu, 23 Jan 2020 07:27:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwyFK4WaXKIbW0czPg7L/LkBqQ50HqF8tgU0B40UJwERF+JwF/uE6WP7ieH99ZcrRaxsWiL X-Received: by 2002:a9d:1b26:: with SMTP id l35mr11747766otl.307.1579793239895; Thu, 23 Jan 2020 07:27:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579793239; cv=none; d=google.com; s=arc-20160816; b=umh3gozw4rdcavwPlSqY1GhB07lOafIEHywQ9RkG6ZEZa46xavqElsNZ3fNDe1i/yI E+OjYj/UJOJf6BjMos9yl7ahflKJ1AKFrbiXIC9IRLOO4a7DsPppb7uJmg2Y/JcZ4r0E z7yso9o0gODVFQrCOar1JafsLeqoluGo1Xf1RL9KcN83Bb8Ws9MoV5mz1UTKRoTuwoc5 +ZvZSnM/Mr3eIvGsQYaOER1kEunXChGw0Cb9Z2sTuXIvrhda5ekiFbS/UHRsCGcKwqhH gftEmnDDUxN/cai2s59gC/WhvMb+Q0T35tD726G8qj2dvB6R79H7CTrCBxTtCmTYHK1A z7Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gr0/iRYX6pdOjlgLU2+c3EE2UdU46bZbHnnZWF6Q8ck=; b=xQq93knkXrWYRRVwAjTVYnzkC5luTHuDPTWXVM27aEcwqVUy3OoJEmx1/6j2m8wYjF izm22vbmnmGg9/reZ1pJzIXF8++kKH4gHCccvRjEsPzelbmBitEcyKtANAt+3xkQV2u1 QZkpnklI/4R2xB/xyLuafWFqKAYa+CCY1BC7hPBCjNGYbP2XJmm3VnO1hoFDnb6ABZ3V y7kYP2mpmBCKC8Tc1JEbJ3jhwMuYZxAvD+KLtS4W326xtXRte3aht/0pKVqZUzDMOo8n fIe385qJLV3Nx82vsmPrIiBF1O710unA/IrZI/9kZTurv1EiI5JEODSJuhCXe8eDNVoM aUaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DhF+pYEn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n14si1210483otk.179.2020.01.23.07.27.08; Thu, 23 Jan 2020 07:27:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DhF+pYEn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729260AbgAWPZ2 (ORCPT + 99 others); Thu, 23 Jan 2020 10:25:28 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:52673 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729235AbgAWPZW (ORCPT ); Thu, 23 Jan 2020 10:25:22 -0500 Received: by mail-pj1-f66.google.com with SMTP id a6so1353155pjh.2 for ; Thu, 23 Jan 2020 07:25:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gr0/iRYX6pdOjlgLU2+c3EE2UdU46bZbHnnZWF6Q8ck=; b=DhF+pYEnaJLadjh0xvWG6frOgofZmY5KGQv0Ra7JLsEmIYIrXaDCwrhLH+KEJB3XfT ZPXMaZmNsnIIzP/K8ifQzl/nqzBDbJJHIzezdOIFmW8aAo2ZHfWGIdpnUcLFQX2WaFEk cAUI+5IeWTtj0jk9HcBsZYznFtXQGXC/FhTYE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gr0/iRYX6pdOjlgLU2+c3EE2UdU46bZbHnnZWF6Q8ck=; b=J8WtB6gkwB8CsZHw3bVudYoPocVgiWnYLmdVnaImYXZbcPrHV/pE6I3TNXiA5DdDT2 +uWuZLdZsBBhEt7ntttkNi66R0+nnQrvkaTfjEbfLs7e0K7Dowe1GhWmw8VQPp+lGjVe JQio8C+BDJG7+s4PCf71f/ZRXs0ku7mNNhZFAgW3FyO/1VBOz/LnQNXceSFnG+4EdNH9 Nu9Pqp8XL86XvVEq/70wswVHYQfbYzpKpObHjEpv6E6RwynJv119altbVAzu30DZubj7 ULfiLRHVE/QwTRK37FCuqjZzCa0fMFwLHuKEL8J5hA2eUlhck6XcNP53l+WcuDZYkVj/ /CJg== X-Gm-Message-State: APjAAAWQzeVWcOHPnfi+eLE3pAo/iXnFvaV/43dZxWBtfDIHRSgHo8da fGr8fBvTVXUXXLMgSD/QTGSKPgVw2iaqRQ== X-Received: by 2002:a17:902:aa05:: with SMTP id be5mr16132824plb.142.1579793121265; Thu, 23 Jan 2020 07:25:21 -0800 (PST) Received: from kpsingh-kernel.localdomain ([2a00:79e1:abc:122:bd8d:3f7b:87f7:16d1]) by smtp.gmail.com with ESMTPSA id v5sm3108118pfn.122.2020.01.23.07.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 07:25:20 -0800 (PST) From: KP Singh To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org Cc: Brendan Jackman , Florent Revest , Thomas Garnier , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Thomas Garnier , Michael Halcrow , Paul Turner , Brendan Gregg , Jann Horn , Matthew Garrett , Christian Brauner , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Florent Revest , Brendan Jackman , Martin KaFai Lau , Song Liu , Yonghong Song , "Serge E. Hallyn" , Mauro Carvalho Chehab , "David S. Miller" , Greg Kroah-Hartman , Nicolas Ferre , Stanislav Fomichev , Quentin Monnet , Andrey Ignatov , Joe Stringer Subject: [PATCH bpf-next v3 07/10] bpf: lsm: Make the allocated callback RO+X Date: Thu, 23 Jan 2020 07:24:37 -0800 Message-Id: <20200123152440.28956-8-kpsingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123152440.28956-1-kpsingh@chromium.org> References: <20200123152440.28956-1-kpsingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: KP Singh This patch is not needed after arch_bpf_prepare_trampoline moves to using text_poke. The two IPI TLB flushes can be further optimized if a new API to handle W^X in the kernel emerges as an outcome of: https://lore.kernel.org/bpf/20200103234725.22846-1-kpsingh@chromium.org/ Signed-off-by: KP Singh Reviewed-by: Brendan Jackman Reviewed-by: Florent Revest Reviewed-by: Thomas Garnier --- security/bpf/hooks.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/security/bpf/hooks.c b/security/bpf/hooks.c index f1d4fdcdb20e..beeeb8c1f9c2 100644 --- a/security/bpf/hooks.c +++ b/security/bpf/hooks.c @@ -190,6 +190,15 @@ static struct bpf_lsm_hook *bpf_lsm_hook_alloc(struct bpf_lsm_list *list, goto error; } + /* First make the page read-only, and only then make it executable to + * prevent it from being W+X in between. + */ + set_memory_ro((unsigned long)image, 1); + /* More checks can be done here to ensure that nothing was changed + * between arch_prepare_bpf_trampoline and set_memory_ro. + */ + set_memory_x((unsigned long)image, 1); + hook = kzalloc(sizeof(struct bpf_lsm_hook), GFP_KERNEL); if (!hook) { ret = -ENOMEM; -- 2.20.1