Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp11023281ybl; Fri, 27 Dec 2019 06:25:29 -0800 (PST) X-Google-Smtp-Source: APXvYqzzMV1JHp1iksv0/1mlS7c8djTqmSJAuonfWCS9TWauFmcphbXTXugkZ+CSupBuXhkrkt4k X-Received: by 2002:aca:bd84:: with SMTP id n126mr3075464oif.99.1577456729535; Fri, 27 Dec 2019 06:25:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577456729; cv=none; d=google.com; s=arc-20160816; b=L0xVT3lHziNAdtfh14a2693EXoRmRvbvKapfhTt6i6PxMrRXFYRe1Ukjp1dZjTu3BO UyasPp+zFBu0gItZOXmHqa3Q9rNh7bzTuK+ORm/VIvGNUSnO4C7YwiWX8gZhCTAfnnOy +bpOqTzdn5ag69HrnNwA2zXs9/ytDUCuMB/g/Qc06SAFFtGxy5FKDAAaV8gxbvNnXugW 1jBFk1sXbEBAvAOm260UQAj1yztYx9mDBQ0ALxJmo5y3f+FVa8T9f4ahmLu2VAWEBRG1 eXcgYS/F642Ts+5w5ZOjgZccDDuV+uCMJxNY2fQCuFloRmiVhbELQZQwhqU/HhwNeXrr 4Q+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=JEcPiC990UIu1o6Rm9PyiqAOwz2kqcjhohkdZ3BkGrk=; b=GTBk6dCRzw6imfkja3bN+nO6+vOyD8in4eHMPl6R7dLiWxYsr8CzNLKwB7Mu8UZz6P sR7uORiF+Pm0W9mE3mnRdpHOLH7LjlfhsUQPcw9f/vU7N7Dj+VqfgSCUHeMQM2f1bGLA 3z4swY+3MBW36ZVz14eYgqWfSbzkTG5fc/1XHagNmu4r3dnG9xBq/PsiDm6IHHdhJhmt 3c3knHOKKaOskrXY/ARwWnAU4pFjb67UzWDbCG1tSvPIa7u45w1rnbJHozLlk4kUYaUw KY2jhrcdhKgUTC5W7TC7wD+2F7J81MS4bIcIad8gnc+P1GzN4PamCV28S/7y7D1Ou+FB 6Hxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=2RpH0Vy1; 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 c24si17454858otf.14.2019.12.27.06.24.53; Fri, 27 Dec 2019 06:25:29 -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=@sargun.me header.s=google header.b=2RpH0Vy1; 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 S1726677AbfL0OW6 (ORCPT + 99 others); Fri, 27 Dec 2019 09:22:58 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:37794 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbfL0OW6 (ORCPT ); Fri, 27 Dec 2019 09:22:58 -0500 Received: by mail-ed1-f65.google.com with SMTP id cy15so25380622edb.4 for ; Fri, 27 Dec 2019 06:22:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JEcPiC990UIu1o6Rm9PyiqAOwz2kqcjhohkdZ3BkGrk=; b=2RpH0Vy1AMF+AI8iyUxD4dx1Wfjzzt9+heTxoJQiSWCsh+nWDkpHXS19CMdvBy8MOa f0/HRfO6cjojWhRfyhAeEFSgmjtmq+GSlpG3SoknjPL+asmIhx06eNsB04KXOBsYmCAc 8Bye4WGZaPnikvaFZkFub9VU918ps2Bgff4Nk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JEcPiC990UIu1o6Rm9PyiqAOwz2kqcjhohkdZ3BkGrk=; b=WvUW8HF8/UDr5vtJVzEMfcKffchlimWwBnOh6cEQyvde0JALLbrkpa7unP1F9qzvaC CeyG6vR59iarZOhY0PBwDXcdCZkpQ/Y1w49Q6Mlc5Exil7YWUIyhVD/okt7nrCmJBBae q6wISSuuBLckivgAftzf1r980J+kXwzR+U+ZTNZDOImsIenLFRgdWAvIoKaDt5b9h0At 1e/pqeAyubfCBtgh4y1cmQcd2CmWkwlxoAibkEm+MoaP6SNPKwm0me5xAtTNdw7sNqN6 92oFlwQXsX/J9r6Fp4l/FGs4dxVFO15HUK6qryTpngccNqLWYteZdHYiebBCSKTpFe3z lqwA== X-Gm-Message-State: APjAAAXSEyHS3SyzRkg5zk6RJAfl4qvwKTH6TmxDWlavu2QfQ9C1v3xY 9J19h81UEfrtHgYkJfBMzrVxab/n5cGwUs6ZFAiU0w== X-Received: by 2002:a17:906:22cf:: with SMTP id q15mr52907186eja.77.1577456576199; Fri, 27 Dec 2019 06:22:56 -0800 (PST) MIME-Version: 1.0 References: <20191225214530.GA27780@ircssh-2.c.rugged-nimbus-611.internal> <20191226115245.usf7z5dkui7ndp4w@wittgenstein> <20191226143229.sbopynwut2hhsiwn@yavin.dot.cyphar.com> <57C06925-0CC6-4251-AD57-8FF1BC28F049@ubuntu.com> <20191227022446.37e64ag4uaqms2w4@yavin.dot.cyphar.com> <20191227023131.klnobtlfgeqcmvbb@yavin.dot.cyphar.com> <20191227114725.xsacnaoaaxdv6yg3@wittgenstein> In-Reply-To: <20191227114725.xsacnaoaaxdv6yg3@wittgenstein> From: Sargun Dhillon Date: Fri, 27 Dec 2019 09:22:20 -0500 Message-ID: Subject: Re: [PATCH] seccomp: Check flags on seccomp_notif is unset To: Christian Brauner Cc: Aleksa Sarai , LKML , Linux API , Tycho Andersen , Jann Horn , Kees Cook Content-Type: text/plain; charset="UTF-8" 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 6:47 AM Christian Brauner wrote: > > On Fri, Dec 27, 2019 at 01:31:31PM +1100, Aleksa Sarai wrote: > > On 2019-12-27, Aleksa Sarai wrote: > > > > Scratch that -- as Tycho just mentioned, there is un-named padding in > > the struct so check_zeroed_user() is the wrong thing to do. But this > > Hm, I don't think so. > I understood Tycho's point as _if_ there ever is padding then this would > not be zeroed. > Right now, there is no padding since the struct is correctly padded: > > struct seccomp_data { > int nr; > __u32 arch; > __u64 instruction_pointer; > __u64 args[6]; > }; > > struct seccomp_notif { > __u64 id; > __u32 pid; > __u32 flags; > struct seccomp_data data; > }; > > which would be - using pahole: > > struct seccomp_data { > int nr; /* 0 4 */ > __u32 arch; /* 4 4 */ > __u64 instruction_pointer; /* 8 8 */ > __u64 args[6]; /* 16 48 */ > > /* size: 64, cachelines: 1, members: 4 */ > }; > struct seccomp_notif { > __u64 id; /* 0 8 */ > __u32 pid; /* 8 4 */ > __u32 flags; /* 12 4 */ > struct seccomp_data data; /* 16 64 */ > > /* size: 80, cachelines: 2, members: 4 */ > /* last cacheline: 16 bytes */ > }; > > The only worry would be a 2byte int type but there's no architecture > we support which does this right now afaict. > > > also will make extensions harder to deal with because (presumably) they > > will also have un-named padding, making copy_struct_from_user() the > > This all will be a non-issue if we just use __u64 for extensions. > > My point about using copy_struct_from_user() was that we should verify > that _all_ fields are uninitialized and not just the flags argument > since we might introduce a flags argument that requires another already > existing member in seccomp_notif to be set to a value. We should do this > change now so we don't have to risk breaking someone in the future. > > I'm trying to get at least Mozilla/Firefox off of their crazy > SECCOMP_RET_TRAP way of implementing their broker onto the user notifier > and they will likely need some extensions. That includes the pidfd stuff > for seccomp that Sargun will likely be doing and the new pidfd_getfd() > syscall. So it's not unlikely that we might need other already existing > fields in that struct to be set to some value. > > I don't particulary care how we do it: > - We can do a simple copy_from_user() and check each field individually. Just doing a simple copy_from_user, and for now, calling memchr_inv on the whole thing. We can drop the memset, and just leave a note to indicate that if unpadded fields are introduced in the future, this structure must be manually zeroed out. Although, this might be laying a trap for ourselves. This leaves us in a good position for introducing a flag field in the future. All we have to do is change the memchr_inv from checking on an entire struct basis to checking on a per-field basis. > - Use copy_struct_from_user(). > That is safe to do right now since there is no padding afaict and > it'll automatically verify new fields as well. > If I understand the worry correctly then the argument against > copy_struct_from_user() here is that there might be padding introduced > and userspace will not do an explicit memset() but rather rely on an > empty inializer {} and will _accidently_ pass down a struct which has > __all fields cleared__ but __uninitialized padding__ and we tell them > EINVAL? That can only happen if we introduce padding in the struct > which I'd argue we just don't do. That'll be in line with what we > require from our ABIs already anyway. > > Christian