Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1111844ybm; Fri, 29 May 2020 22:27:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3k6TgaNkY3RoUdh6hMKedsvABGOhMBnvkuNMVImVw9p1Fwdq5iAq17wwn1wMmyopIoD12 X-Received: by 2002:aa7:c598:: with SMTP id g24mr5593503edq.132.1590816441175; Fri, 29 May 2020 22:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590816441; cv=none; d=google.com; s=arc-20160816; b=siuzynYx2Qh6zkmi8YcmGxnnVQZORRCHJaGcXzUwYjTqDidVyTUuX7O35x8CrfKALD A7QH296YW/Whc5QscC00bhNA4Xt92YEwHTrlz6Jc+cqhG7V7wXGFEIcNFjPuQYYuKgDB vZBuBYAGoHynHxRg1GOJrLgpg3oJFYqDwYkz38NfAGHepXk8IX5REtdAn387smldIRsV I0iRmfNk8V7w4+18V6sL1kjk8H4dNhS63OwMRq8bxmLhj3MoV4tJw0cIGU9b8M72fJXf 9hoWWedWVCKP5TyvQeDbFAT0tsjsUTdmT5J4rYfqcLJCVBy/PmRa39Oy168Ig+2mVgTT cq7Q== 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:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=fjf8hmDqJIojxT3nGa3YLDxLqUzBCgpmNXNwU1GHXcw=; b=iB4PjEycELeqRuPRI4lNmjwJ0KyOZ/m+jPA46aBhNhM3CB60t7xPPeghnqTQWC8Wsf iZqcBAqBtU5c4BfdtE69gSLWgggJAe2iashugbrYBG7kuuazyJ7jhCoYx7fpmL4xHuZ8 8yHZ8r4nR2pxJ5Ri16WmrsB49WRnRY7V+EsyWxFfHkakSIK51QGLrNuk8K3GANAIg5OU 12fw2GVuZV0dgCddz59Csv8Bt1sbdSC0X9jB2vie6J2rTTyxA2jDi318CW6FCvunxxL7 bK/eDaZJhX71oJVE89fR9BvvjhfQPZBCypH+cmyJkQuL0UJ57z3dS7wbWPQQqADl8L4z GO1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Qxjbd0gA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id b25si8338712edn.602.2020.05.29.22.26.55; Fri, 29 May 2020 22:27:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Qxjbd0gA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1725950AbgE3FWo (ORCPT + 99 others); Sat, 30 May 2020 01:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbgE3FWo (ORCPT ); Sat, 30 May 2020 01:22:44 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E18A9C08C5C9 for ; Fri, 29 May 2020 22:22:42 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id fs4so2346531pjb.5 for ; Fri, 29 May 2020 22:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fjf8hmDqJIojxT3nGa3YLDxLqUzBCgpmNXNwU1GHXcw=; b=Qxjbd0gA7K0cZxfT1oEnXcWuM5WEpVNrRQkEbIm5j8VgzEjHxQL9Z6Xa5Ow/U8W9Ea EY/FK4MS0uiTPKyekupYVR2OL5fau2dywLiwgmrT7WLaMH71pMtDpGf+8tBB1Hhy2qn1 IMbTRrhDvC6eW2kwG7lqyGzoscIEji+3JuT+c= 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; bh=fjf8hmDqJIojxT3nGa3YLDxLqUzBCgpmNXNwU1GHXcw=; b=RToMLHHs5xx20OkxnpPeWbKiFRckJnmzt4Gg+GHHgOQCfOHBjZkL4NZUurMOx9v1pC trxlCeZfPCVQ3qQG4EbPdjaR+sixzP2o6k4e3SXPIXYhPV+RB3AcBq0CAhWbrCs1rBZS vbJP/wvnbwBor5trCPD8Y6rU+/4ctgiSc9pOWYAAjNmsA6XvX+Ezfq0GLqy1HfRgf//X 09pN/mEdCXf/5CUHlr5+mgYrYNnJrUWedcmra8m7JGlmgK4YCgNAsiLepvBwWFvz7txM 2H6529xExKsUVIqm7rpIeg5QoEj9tL1pBOF42I3PUOO1bfQ+I1rbsU3UmqH2/VpKSJM+ ZkTg== X-Gm-Message-State: AOAM533ocsE2AJr6s33ZEMYaWO3Y/KaUEBpjqtcCnqJ5BDs6gvW87gzr aal9li+SJTM5JE4YWXYwaZeTjQ== X-Received: by 2002:a17:902:ba8d:: with SMTP id k13mr11675754pls.290.1590816162350; Fri, 29 May 2020 22:22:42 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q44sm986162pja.29.2020.05.29.22.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 22:22:41 -0700 (PDT) Date: Fri, 29 May 2020 22:22:40 -0700 From: Kees Cook To: Jann Horn Cc: Sargun Dhillon , Christian Brauner , Linux Containers , Aleksa Sarai , Jeffrey Vander Stoep , Linux API , kernel list , Chris Palmer , Robert Sesek , Tycho Andersen , Matt Denton , Al Viro Subject: Re: [PATCH v2 2/3] seccomp: Introduce addfd ioctl to seccomp user notifier Message-ID: <202005292219.C9B1BF33@keescook> References: <20200528110858.3265-1-sargun@sargun.me> <20200528110858.3265-3-sargun@sargun.me> <202005282345.573B917@keescook> <20200530011054.GA14852@ircssh-2.c.rugged-nimbus-611.internal> <202005291926.E9004B4@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 30, 2020 at 05:17:24AM +0200, Jann Horn wrote: > On Sat, May 30, 2020 at 4:43 AM Kees Cook wrote: > > I mean, yes, that's certainly better, but it just seems a shame that > > everyone has to do the get_unused/put_unused dance just because of how > > SCM_RIGHTS does this weird put_user() in the middle. > > > > Can anyone clarify the expected failure mode from SCM_RIGHTS? Can we > > move the put_user() after instead? > > Honestly, I think trying to remove file descriptors and such after > -EFAULT is a waste of time. If userspace runs into -EFAULT, userspace > is beyond saving and can't really do much other than exit immediately. > There are a bunch of places that will change state and then throw > -EFAULT at the end if userspace supplied an invalid address, because > trying to hold locks across userspace accesses just in case userspace > supplied a bogus address is kinda silly (and often borderline > impossible). Logically, I agree. I'm more worried about the behavioral change -- if we don't remove the fd on failure, the fd is installed with no indication to the process that it exists (it won't know the close it -- if it keeps running -- and it may survive across exec). Before, it never entered the file table. > You can actually see that even scm_detach_fds() currently just > silently swallows errors if writing some header fields fails at the > end. Yeah, and it's a corner case. But it should be possible (trivial, even) to clean up on failure to retain the original results. -- Kees Cook