Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3643957ybk; Tue, 19 May 2020 09:30:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEHoTJS54ogrF3FnoJVKVIIlBMCMa9qRe/p4JURm2+e4PdxL+ulgsAZxNhMuXEHb9aKjCP X-Received: by 2002:aa7:d718:: with SMTP id t24mr18940733edq.29.1589905819774; Tue, 19 May 2020 09:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589905819; cv=none; d=google.com; s=arc-20160816; b=Jt6dHm9FFCtWgsWJ2kocmPuRrygGQa9i/7oU+fwuc3rsUlVlSldQxwRNGLHeIJZnkR 2Pomvp0B7xsQm0k3Lvm0WlMYKftNQ8JE9LjExlo1LoC/hnGDXDaXV8TQ5X0NGzUDhPni 4oLSRfL6Zd3YYa3cOWvoK0MW0zALkplD22PNLbWynX1oOSgkyxuBbZOLh3W+Lqo/Uoo3 jMNZTTXbL1ACv/eD8nSdU/C4b36ORKRhLbRN256SbyhxSGPYw4YiuPfMCvMZ/ZhNvfqs I1muvN1s6EggQljvNPOYFE9xc2hpuCEy2xuOH72pVLnvZa/WmH532kX0WNYlEG0W/11c Pcgg== 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=kDaF8zyZTb3Ta49NCK5A63qXcN8gydwJuZQlr41/Oy8=; b=Gt83pTIkcYQ2aIRRwK0pUXQEjmohe0RHWGhii5xok7BrqEqQvdukolWNjnVvcU9ka7 EmhMv7aVNGm28JJ/3LmwYG0BLb14PSxaFZ4+/ZrOp24CovDmLT9P2Er2OtpGbAgAFZXP HjWBuKZGBMMMddw1RWFq1dgfBXRq1JIREG62penx7P0doBvlbJq6BMvhAiYgsr4nNFMD pZJVbk4CIj/jRUW8MbBb7HRvu2RwtM37uSJn847QXsxOM9DWoKodo2OEfcE2l+jx9ot2 wXNXpwXY9lwh16k0qMWUu+Rc/cCuM4FBJ76c+Eg5Ra6y9JwXxaNpRBuyV6k3d615JsrI PDnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=O1QETDhp; 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 bz10si121852ejc.507.2020.05.19.09.29.56; Tue, 19 May 2020 09:30:19 -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=O1QETDhp; 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 S1729392AbgESQ0L (ORCPT + 99 others); Tue, 19 May 2020 12:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729340AbgESQ0J (ORCPT ); Tue, 19 May 2020 12:26:09 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58CF9C08C5C0 for ; Tue, 19 May 2020 09:26:09 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id a5so1614800pjh.2 for ; Tue, 19 May 2020 09:26:09 -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=kDaF8zyZTb3Ta49NCK5A63qXcN8gydwJuZQlr41/Oy8=; b=O1QETDhpWINpx9qXOpoLNVjfTGd96i8BxobEwfwNRfKkNpVmJLVykZTQUhodidSGmJ WSliMm3RbgtYth7tcFgdCKpxcpqCdnATzK1fJjMflEOY0r+m11P1uzV6DJVkUmwtV1hb tjnNid9N19+QMXPTuHpDakBiFJmHE/XUVu68g= 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=kDaF8zyZTb3Ta49NCK5A63qXcN8gydwJuZQlr41/Oy8=; b=jZWIAzPLwO5GUqtlslgKW8j1bl+a0eA9ieoGo3O5iPpjk0wOvINDrUDdTfehckhS+E kHOrERfa1BqnSFczI7Cxj/oBvdOZ4S48O2GX0LuOs7MsLBsVzP09YWMBdYn3Ji7x74Wc QAj0Mw2LZ9m/u3wOXCQDrwFPGGz4A77RhBsXv4r23iwAfEcfgGFb4A9e742tVMxRn/9r 557kUdPAlnXBVplugWHoRfs3VGpenmBMaQkntlmjnXTX1noC9s5pnaBhiqwJ8CnWlAfk pfc9Vhz20amMeYTxgkqv0m+SqL9ilbmQXDHDiwhEIm6aY+uA7zpu/0Zz7JWq4lCVOyvO +DHw== X-Gm-Message-State: AOAM530TpjfGi93TsGvNVzklGRArNrSaUXN1xAcLYspq+aS/soN0bM58 V13vvWWHI2qBZKsWC/rP76ScSQ== X-Received: by 2002:a17:90a:dc10:: with SMTP id i16mr333818pjv.137.1589905567075; Tue, 19 May 2020 09:26:07 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f136sm12823pfa.59.2020.05.19.09.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 09:26:05 -0700 (PDT) Date: Tue, 19 May 2020 09:26:04 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: Al Viro , Andrew Morton , Tetsuo Handa , Eric Biggers , Dmitry Vyukov , linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/4] Relocate execve() sanity checks Message-ID: <202005190918.D2BD83F7C@keescook> References: <20200518055457.12302-1-keescook@chromium.org> <87a724t153.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a724t153.fsf@x220.int.ebiederm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 19, 2020 at 10:06:32AM -0500, Eric W. Biederman wrote: > Kees Cook writes: > > > Hi, > > > > While looking at the code paths for the proposed O_MAYEXEC flag, I saw > > some things that looked like they should be fixed up. > > > > exec: Change uselib(2) IS_SREG() failure to EACCES > > This just regularizes the return code on uselib(2). > > > > exec: Relocate S_ISREG() check > > This moves the S_ISREG() check even earlier than it was already. > > > > exec: Relocate path_noexec() check > > This adds the path_noexec() check to the same place as the > > S_ISREG() check. > > > > fs: Include FMODE_EXEC when converting flags to f_mode > > This seemed like an oversight, but I suspect there is some > > reason I couldn't find for why FMODE_EXEC doesn't get set in > > f_mode and just stays in f_flags. > > So I took a look at this series. > > I think the belt and suspenders approach of adding code in open and then > keeping it in exec and uselib is probably wrong. My sense of the > situation is a belt and suspenders approach is more likely to be > confusing and result in people making mistakes when maintaining the code > than to actually be helpful. This is why I added the comments in fs/exec.c's redundant checks. When I was originally testing this series, I had entirely removed the checks in fs/exec.c, but then had nightmares about some kind of future VFS paths that would somehow bypass do_open() and result in execve() working on noexec mounts, there by allowing for the introduction of a really nasty security bug. The S_ISREG test is demonstrably too late (as referenced in the series), and given the LSM hooks, I think the noexec check is too late as well. (This is especially true for the coming O_MAYEXEC series, which will absolutely need those tests earlier as well[1] -- the permission checking is then in the correct place: during open, not exec.) I think the only question is about leaving the redundant checks in fs/exec.c, which I think are a cheap way to retain a sense of robustness. -Kees [1] https://lore.kernel.org/lkml/202005142343.D580850@keescook/ -- Kees Cook