Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp29635imm; Fri, 21 Sep 2018 17:25:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV60mDK06Sn8QRgZVIsCWbzQh8AwBbhJle7+wGh/axwjeknwlEugrMlpI5Uvbqvk/QhMnadtJ X-Received: by 2002:a17:902:aa8f:: with SMTP id d15-v6mr141144plr.64.1537575945799; Fri, 21 Sep 2018 17:25:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575945; cv=none; d=google.com; s=arc-20160816; b=Ruaqh+HC/SKYJ1BJVCBjtJLVKtuUQaejeeBrnbenshXVcYqln7TdyLLpC6mLLJEZl5 5hQBqA7YRqNQhfkEsXXaGo67wZyCdzAR3i6n38gx/IQZCgH3i0Vjougw/fxhxTKcBx5y oZ3mOKLYicfXz5y3k5X499JPLUI6idkoPMNzHbkL6nBe8UzqctJk7knkDYJZo9xpGMVx ODd7joGaISgHE0IPRXhA/fiJjYYzOOGBZXaDikd9hGYEvu6/UrpzfKlLxCOUfyFttZBn CJ9R2ddt0AWbMj9rd+n/wj1IMV1Q+EsVOjzS60YCnM9lrecnKk12M2WXsqv8MpJjPkzV Ml3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=XwgdGlTq2zAdVszi4fIBYm/ekUf2NqMdi088d6iVfY0=; b=H93IHYQ0RZKTunFd/SAgNrm5U8iSTDIonxLAJaQwLVVY9+EHWDqHKYNkDHKGTTZ9EA yO7jpUDrV8bomQWXPzjPfkVg3SHTrZW+FtgdvDgzRjqOtTQUcnTuNTO1iwAvpd8WtB3z HRDLykUDQgs3ab5NXPLNIozzq+QRNjpSIBhNm5xDBmiDWN8ma3ryqZeRJEKGF3oM4Hmj EunOYIXify/ZaBoSccugsXayxobSlgc8KdcIGXmtkHvOhBMAemGMTULDq+pVlM126pnq mw3Ah0dWwLaTAdMEwgYYbyiCgLzhTk+YQe3e0TZ/Xy8UJwgxbnZKEHr1WEd/EAd0ewes Op0A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i21-v6si4204265pgh.53.2018.09.21.17.25.30; Fri, 21 Sep 2018 17:25:45 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391997AbeIVGKr (ORCPT + 99 others); Sat, 22 Sep 2018 02:10:47 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44134 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391930AbeIVGKp (ORCPT ); Sat, 22 Sep 2018 02:10:45 -0400 Received: from [2a02:8011:400e:2:cbab:f00:c93f:614] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1g3Vdv-0008BU-5G; Sat, 22 Sep 2018 01:19:27 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1g3Vdp-0000u7-2A; Sat, 22 Sep 2018 01:19:21 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Andy Lutomirski" , "Oleg Nesterov" , "Kees Cook" Date: Sat, 22 Sep 2018 01:15:42 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 55/63] seccomp: extract check/assign mode helpers In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:cbab:f00:c93f:614 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.58-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook commit 1f41b450416e689b9b7c8bfb750a98604f687a9b upstream. To support splitting mode 1 from mode 2, extract the mode checking and assignment logic into common functions. Signed-off-by: Kees Cook Reviewed-by: Oleg Nesterov Reviewed-by: Andy Lutomirski Signed-off-by: Ben Hutchings --- kernel/seccomp.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -194,7 +194,23 @@ static u32 seccomp_run_filters(int sysca } return ret; } +#endif /* CONFIG_SECCOMP_FILTER */ +static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode) +{ + if (current->seccomp.mode && current->seccomp.mode != seccomp_mode) + return false; + + return true; +} + +static inline void seccomp_assign_mode(unsigned long seccomp_mode) +{ + current->seccomp.mode = seccomp_mode; + set_tsk_thread_flag(current, TIF_SECCOMP); +} + +#ifdef CONFIG_SECCOMP_FILTER /** * seccomp_attach_filter: Attaches a seccomp filter to current. * @fprog: BPF program to install @@ -490,8 +506,7 @@ static long seccomp_set_mode(unsigned lo { long ret = -EINVAL; - if (current->seccomp.mode && - current->seccomp.mode != seccomp_mode) + if (!seccomp_may_assign_mode(seccomp_mode)) goto out; switch (seccomp_mode) { @@ -512,8 +527,7 @@ static long seccomp_set_mode(unsigned lo goto out; } - current->seccomp.mode = seccomp_mode; - set_thread_flag(TIF_SECCOMP); + seccomp_assign_mode(seccomp_mode); out: return ret; }