Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9922130ybl; Thu, 26 Dec 2019 07:38:49 -0800 (PST) X-Google-Smtp-Source: APXvYqyC4U5/f6Aj6zLVZ8RIXcrZDs2NHzFGzJ2Sz7qCLzszgFa4LR7nXOtbWLhuBktemfw5/zI2 X-Received: by 2002:a9d:4e92:: with SMTP id v18mr35542223otk.47.1577374729034; Thu, 26 Dec 2019 07:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577374729; cv=none; d=google.com; s=arc-20160816; b=KaEYm7PcThZe4eYN2Vd+8PyRLk68BH3o5zr0mVJnsx0wLiwhkzsWQqe56RqG5auTj6 F5T2RsfJR48ahT+Kkk9nH/3KYRaP0epNzJKv2C8VMq3affoQeP0tx2b+SHctvxHwayf7 GK1fOePKZVSSKxU59fwdg/UBy2f0Vb7hTJaVDUNIiTjGjifMhjl2wd6JmgrMLlQ6GGqh /IhTZo67vXGhuI/+s4xROKWXDANK1FJDP9+U+8mTiSglHTH4nmUY9HwblY4Y5newBJwr v1awRsnFptymEL+m+PQlCVBh6uX9FiIamDkHdBIollRBgYKnyh3xi8yi5pLEyRy3A03H 6YPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5O98/Q8hWNM3RNsrmMXZZkSL0QH2EUkHvO2fSlNMHBU=; b=GR26hrS7FjbYXEbtIW/S4d2aIKs4IADj+UNOArNbaCpH/Ag/Yv6mw7P3PK4CKoXBc6 2+96GXfWEE0Qs8dKACeomMJPusYVJnIIqxpj3qCW6lw5K1uHvGRerzFwZzw35u94ivAU VsEnqqGIciqgejlQHPBtuAmH1y2kBc3JPU+JCU3dDy4TU2hJolxKrLeix+hI5DXKkIWC mOQ+hODG2Y5uKovStT7azJRNJcWsstpgDKq/oxZBF8Z+dH69rQzL6LJhLj79gGJbmZPo dZ8nu6/Cr1Q1WSgDxIiA2UU60VC3GXi0Tp84TEBZzZOJ1t+bOXgtAit/23flg+yQ8FV7 yRPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b="v2J/ldUG"; 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 h28si19048999otg.63.2019.12.26.07.38.37; Thu, 26 Dec 2019 07:38:49 -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=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b="v2J/ldUG"; 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 S1726659AbfLZPh6 (ORCPT + 99 others); Thu, 26 Dec 2019 10:37:58 -0500 Received: from mail-io1-f68.google.com ([209.85.166.68]:35061 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726236AbfLZPh6 (ORCPT ); Thu, 26 Dec 2019 10:37:58 -0500 Received: by mail-io1-f68.google.com with SMTP id v18so23554032iol.2 for ; Thu, 26 Dec 2019 07:37:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5O98/Q8hWNM3RNsrmMXZZkSL0QH2EUkHvO2fSlNMHBU=; b=v2J/ldUG0+9s2t9PIkHIgh3DVPfToU/LOwGE0g36pH/UgYT3h1Djd1EYMYfzG7X6Z0 SqUa/bzgoe4+yDdF4oS+UEWBDmuTVphm0zkQx/KfGJhXAIDWxwPl6tkOzsD/odqqll8V uFlTycY5rfDVXxbENe0ofDFUc0oQ7AB/UsUX5CT7FjQNVOu+GtRiCz3IfQX5EWt/5x2l xzv/WqcnZVSJBli71H87/FW4Ky3uxo6WjLilkGSr1peqwGsrO1LDrwCbDVOcc1F2OKAS 6Rdb2iGVSeLEBe6YrZcRs02aA+RENqO/1afLeXjRPE5yZZ2m8QQO3IBD/joLqHTdvPIJ WZlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=5O98/Q8hWNM3RNsrmMXZZkSL0QH2EUkHvO2fSlNMHBU=; b=ESHOZKBZdxbf3IBwnsu1auUUXPdTEakjP8CmFZeqn+lejV8ZqPSRBKk9D88rqMOE0G HuCQIa05+JpEqRadBH7Yloa39PExnSsrgb3zRTHRdIM3MyNzoU5DzApAqcXli27+6EMf 1PfrGwPxya26uuua9tA8ORYZZ0rAlPOAb2gyNie30AbegkLc/K4yebdvwCO+BkyP/IxT G1pc/z9wr/KeknUjCEUf6LWNBkfYNIxH61hjgGflaTh2TD+rFclRDXtR6w0tlaHS5CLD hG9cTIza72au9PzFJoxg2CudRz8FrFJBY3AW9tbMDwoATZm2a4J1foea7YhiiDqH7tQi yUGw== X-Gm-Message-State: APjAAAXVywq4d9QYm88vhQSAbtl45P8YJjP8M5CiHASEmGS96PxY1Ndy zSQvgCyy1vMijI74MwVq8PIeCQ== X-Received: by 2002:a02:9988:: with SMTP id a8mr37790039jal.33.1577374677172; Thu, 26 Dec 2019 07:37:57 -0800 (PST) Received: from cisco ([2601:282:902:b340:f166:b50c:bba2:408]) by smtp.gmail.com with ESMTPSA id 81sm12270971ilx.40.2019.12.26.07.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Dec 2019 07:37:56 -0800 (PST) Date: Thu, 26 Dec 2019 08:37:53 -0700 From: Tycho Andersen To: Aleksa Sarai Cc: Christian Brauner , Sargun Dhillon , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, jannh@google.com, keescook@chromium.org Subject: Re: [PATCH] seccomp: Check flags on seccomp_notif is unset Message-ID: <20191226153753.GA15663@cisco> References: <20191225214530.GA27780@ircssh-2.c.rugged-nimbus-611.internal> <20191226115245.usf7z5dkui7ndp4w@wittgenstein> <20191226143229.sbopynwut2hhsiwn@yavin.dot.cyphar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191226143229.sbopynwut2hhsiwn@yavin.dot.cyphar.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 27, 2019 at 01:32:29AM +1100, Aleksa Sarai wrote: > On 2019-12-26, Christian Brauner wrote: > > On Wed, Dec 25, 2019 at 09:45:33PM +0000, Sargun Dhillon wrote: > > > This patch is a small change in enforcement of the uapi for > > > SECCOMP_IOCTL_NOTIF_RECV ioctl. Specificaly, the datastructure which is > > > passed (seccomp_notif), has a flags member. Previously that could be > > > set to a nonsense value, and we would ignore it. This ensures that > > > no flags are set. > > > > > > Signed-off-by: Sargun Dhillon > > > Cc: Kees Cook > > > > I'm fine with this since we soon want to make use of the flag argument > > when we add a flag to get a pidfd from the seccomp notifier on receive. > > The major users I could identify already pass in seccomp_notif with all > > fields set to 0. If we really break users we can always revert; this > > seems very unlikely to me though. > > > > One more question below, otherwise: > > > > Reviewed-by: Christian Brauner > > > > > --- > > > kernel/seccomp.c | 7 +++++++ > > > 1 file changed, 7 insertions(+) > > > > > > diff --git a/kernel/seccomp.c b/kernel/seccomp.c > > > index 12d2227e5786..455925557490 100644 > > > --- a/kernel/seccomp.c > > > +++ b/kernel/seccomp.c > > > @@ -1026,6 +1026,13 @@ static long seccomp_notify_recv(struct seccomp_filter *filter, > > > struct seccomp_notif unotif; > > > ssize_t ret; > > > > > > + if (copy_from_user(&unotif, buf, sizeof(unotif))) > > > + return -EFAULT; > > > + > > > + /* flags is reserved right now, make sure it's unset */ > > > + if (unotif.flags) > > > + return -EINVAL; > > > + > > > > Might it make sense to use > > > > err = copy_struct_from_user(&unotif, sizeof(unotif), buf, sizeof(unotif)); > > if (err) > > return err; > > > > This way we check that the whole struct is 0 and report an error as soon > > as one of the members is non-zero. That's more drastic but it'd ensure > > that other fields can be used in the future for whatever purposes. > > It would also let us get rid of the memset() below. > > Given that this isn't an extensible struct, it would be simpler to just do > check_zeroed_user() -- copy_struct_from_user() is overkill. That would > also remove the need for any copy_from_user()s and the memset can be > dropped by just doing > > struct seccomp_notif unotif = {}; This doesn't zero the padding according to the C standard, so no, you can't drop the memset, or you may leak kernel stack bits. As for the rest of it, while it is an ABI change I think all of the users are CC'd on this thread, and it's an obvious goof on my part :). So: Acked-by: Tycho Andersen Tycho