From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-f67.google.com ([209.85.161.67]:40849 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725924AbeI1FbO (ORCPT ); Fri, 28 Sep 2018 01:31:14 -0400 Received: by mail-yw1-f67.google.com with SMTP id z143-v6so1835147ywa.7 for ; Thu, 27 Sep 2018 16:10:32 -0700 (PDT) Received: from mail-yw1-f50.google.com (mail-yw1-f50.google.com. [209.85.161.50]) by smtp.gmail.com with ESMTPSA id m18-v6sm3855264ywh.63.2018.09.27.16.10.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 16:10:30 -0700 (PDT) Received: by mail-yw1-f50.google.com with SMTP id e201-v6so1846115ywa.3 for ; Thu, 27 Sep 2018 16:10:30 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180927224839.GF15491@cisco.cisco.com> References: <20180927151119.9989-1-tycho@tycho.ws> <20180927151119.9989-2-tycho@tycho.ws> <20180927224839.GF15491@cisco.cisco.com> From: Kees Cook Date: Thu, 27 Sep 2018 16:10:29 -0700 Message-ID: Subject: Re: [PATCH v7 1/6] seccomp: add a return code to trap to userspace To: Tycho Andersen , Stephane Graber Cc: LKML , Linux Containers , Linux API , Andy Lutomirski , Oleg Nesterov , "Eric W . Biederman" , "Serge E . Hallyn" , Christian Brauner , Tyler Hicks , Akihiro Suda , Jann Horn , "linux-fsdevel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Thu, Sep 27, 2018 at 3:48 PM, Tycho Andersen wrote: > On Thu, Sep 27, 2018 at 02:31:24PM -0700, Kees Cook wrote: >> On Thu, Sep 27, 2018 at 8:11 AM, Tycho Andersen wrote: >> struct seccomp_notif { >> __u16 len; /* 0 2 */ >> >> /* XXX 6 bytes hole, try to pack */ >> >> __u64 id; /* 8 8 */ >> __u32 pid; /* 16 4 */ >> __u8 signaled; /* 20 1 */ >> >> /* XXX 3 bytes hole, try to pack */ >> >> struct seccomp_data data; /* 24 64 */ >> /* --- cacheline 1 boundary (64 bytes) was 24 bytes ago --- */ >> >> /* size: 88, cachelines: 2, members: 5 */ >> /* sum members: 79, holes: 2, sum holes: 9 */ >> /* last cacheline: 24 bytes */ >> }; >> struct seccomp_notif_resp { >> __u16 len; /* 0 2 */ >> >> /* XXX 6 bytes hole, try to pack */ >> >> __u64 id; /* 8 8 */ >> __s32 error; /* 16 4 */ >> >> /* XXX 4 bytes hole, try to pack */ >> >> __s64 val; /* 24 8 */ >> >> /* size: 32, cachelines: 1, members: 4 */ >> /* sum members: 22, holes: 2, sum holes: 10 */ >> /* last cacheline: 32 bytes */ >> }; >> >> How about making len u32, and moving pid and error above "id"? This >> leaves a hole after signaled, so changing "len" won't be sufficient >> for versioning here. Perhaps move it after data? > > I'm not sure what you mean by "len won't be sufficient for versioning > here"? Anyway, I can do some packing on these; I didn't bother before > since I figured it's a userspace interface, so saving a few bytes > isn't a huge deal. I was thinking the "len" portion was for determining if the API ever changes in the future. My point was that given the padding holes, e.g. adding a u8 after signaled, "len" wouldn't change, so the kernel might expect to starting reading something after signaled that it wasn't checking before, but the len would be the same. >> I have to say, I'm vaguely nervous about changing the semantics here >> for passing back the fd as the return code from the seccomp() syscall. >> Alternatives seem less appealing, though: changing the meaning of the >> uargs parameter when SECCOMP_FILTER_FLAG_NEW_LISTENER is set, for >> example. Hmm. > > From my perspective we can drop this whole thing. The only thing I'll > ever use is the ptrace version. Someone at some point (I don't > remember who, maybe stgraber) suggested this version would be useful > as well. Well that would certainly change the exposure of the interface pretty drastically. :) So, let's talk more about this, as it raises another thought I had too: for the PTRACE interface to work, you have to know specifically which filter you want to get notifications for. Won't that be slightly tricky? > Anyway, let me know if your nervousness outweighs this, I'm happy to > drop it. I'm not opposed to keeping it, but if you don't think anyone will use it ... we should probably drop it just to avoid the complexity. It's a cool API, though, so I'd like to hear from others first before you go tearing it out. ;) (stgraber added to CC) >> It is possible (though unlikely given the type widths involved here) >> for unotif = {} to not initialize padding, so I would recommend an >> explicit memset(&unotif, 0, sizeof(unotif)) here. > > Orly? I didn't know that, thanks. Yeah, it's a pretty annoying C-ism. The spec says that struct _members_ will get zero-initialized, but it doesn't say anything about padding. >_< In most cases, the padding gets initialized too, just because of bit widths being small enough that they're caught in the member initialization that the compiler does. But for REALLY big holes, they may get missed. In this case, while the padding is small, it's directly exposed to userspace, so I want to make it robust. >> > + if (copy_from_user(&size, buf, sizeof(size))) >> > + return -EFAULT; >> > + size = min_t(size_t, size, sizeof(resp)); >> > + if (copy_from_user(&resp, buf, size)) >> > + return -EFAULT; >> >> For sanity checking on a double-read from userspace, please add: >> >> if (resp.len != size) >> return -EINVAL; > > Won't that fail if sizeof(resp) < resp.len, because of the min_t()? Ah, true. In that case, probably do resp.len = size to avoid any logic failures due to the double-read? I just want to avoid any chance of confusing the size and actually using it somewhere. -Kees -- Kees Cook Pixel Security