Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp310654ybk; Fri, 15 May 2020 01:05:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxplaHLzzd0fqGGmAyVRXIKxw/t+D8y92e17kwRSsPcdJNrjdgJgMRVIIA3AdqF8unPRtGP X-Received: by 2002:a05:6402:30ad:: with SMTP id df13mr1662830edb.339.1589529939208; Fri, 15 May 2020 01:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589529939; cv=none; d=google.com; s=arc-20160816; b=i0tq7hzudRPmcFauW06XLmcNZj1KKh+De7jxAs9zkY6VoTzyTlVOCTvAlRQx3CwXyD 7F9cw5u8gSy6zdNXRhSiy+9cRvAtWLO/2nykiFKBVrWK6YwCZnuZmU6E0SQpmDAw+wwH KhgS54xl43VSa9Gpmlqk04bQrICwH0S/YKCjBTkRXjMvevW6CslXNuYF7gKz9jnR9oA8 D/mMRj7/jOKeG+Kl/mBZvgmhTUb0bQlHVvwAgXZjX9xgzflMTD9npTqT4th5Q5V8E1/9 Rrhg7AWPNlxhQqK0anDAAqCJHOsH7zyi+Ax3Kg1YSCNr2EaYZ4fwzl0t0Fy2/YwKvY3U CcBA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Ur+hb+yciYy1xQ68pS5XyzW31c915My4tqJ2beLm4bQ=; b=fJ6cmhNYM45GRZ1fmtHvaBVhobsfPXFTQrP+Egv/nZ4vQzr52goOyc/NqXM+5kNlrE ycStOYPnF9hLyoNMK9ecl194LMN8u5XQoU0wJIKGNpGiuQrK+CY2+df67BJcrffCMM+1 lBioRrneqfkwpD9lGXzGxGpfj4hpklM7WN/331ykDBWXCLlqt/dsxGODYFp7ssodXyN7 NeFPetKLcYOk1myAOccWWBD7ItJ54wF8POnSzQcbpZbDZXe6MD0pIsc5l9RuJRZjxFv2 Nq8cXOllVu1pFi9hCZ7lL+Bi48+vUrSxfms8a1vwMFbW4IeGStX2kFv+N1lCg7CAW0B8 F7MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lKBBB6TB; 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 n19si742610ejc.415.2020.05.15.01.05.15; Fri, 15 May 2020 01:05:39 -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=lKBBB6TB; 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 S1727772AbgEOIBg (ORCPT + 99 others); Fri, 15 May 2020 04:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726694AbgEOIBf (ORCPT ); Fri, 15 May 2020 04:01:35 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E737C05BD0A for ; Fri, 15 May 2020 01:01:35 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id 145so591628pfw.13 for ; Fri, 15 May 2020 01:01:35 -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:content-transfer-encoding:in-reply-to; bh=Ur+hb+yciYy1xQ68pS5XyzW31c915My4tqJ2beLm4bQ=; b=lKBBB6TBcN0o1HU4UgdMxAG6vhpa1qK6VNim7Q3I07ra18sLY43itwc35OZNGOPACS ymYWlFxO9PvwCf0zrIQ1pxa6GzHHGDHo1jgwyp6aBR8wZKa0Hx5uKMGpHEAZGyjeZ8iK mxsL/SfdN7bkAODR1xFfclPFJE9UsG7Mt5GjM= 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:content-transfer-encoding :in-reply-to; bh=Ur+hb+yciYy1xQ68pS5XyzW31c915My4tqJ2beLm4bQ=; b=Jfm5wr95YsxiOs5SGFapsmgtBhsdlzyykQsq+np9GNQb1HW595GapdTY5IknHbi4jX nyvBP//BEBoBsXrG80E4ezzJa0ZWForhsU4chEcpHSl1a6VxdefqF6rsrQdy2mHrioqs /4ZKpk2vPlD8hVu/2VNNoacjpaijLEde7abBu5LbmF3BGPMHdmYlFkY2IsVw0wdzS/E1 UjErAU1ehkYAMdxIUs9ycmdZmYqydsp4x39jbn0rPe2NyzesXy4yxi2kjy4A4lgTMYvb KvGjH201zZWyDm/nhYvmrhj6h9RSTZxjMRl6AxM/fkMjnEyM8e6k0U/TwazhZuD312xM +hXQ== X-Gm-Message-State: AOAM531I/IMUOP1KFa8hjnVs4fFy4UjOC1MQeM08WJ2twpYniDOr49iE xB1H09sscZctEvFj4rI+B5ihmQ== X-Received: by 2002:a63:f958:: with SMTP id q24mr1977355pgk.338.1589529694841; Fri, 15 May 2020 01:01:34 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id o7sm1178366pgs.35.2020.05.15.01.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 01:01:33 -0700 (PDT) Date: Fri, 15 May 2020 01:01:32 -0700 From: Kees Cook To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: Al Viro , Aleksa Sarai , Andy Lutomirski , Mimi Zohar , Stephen Smalley , Christian Heimes , Deven Bowers , Tetsuo Handa , John Johansen , Kentaro Takeda , "Lev R. Oshvang ." , Alexei Starovoitov , Daniel Borkmann , Eric Chiang , Florian Weimer , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Lakshmi Ramasubramanian , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Philippe =?iso-8859-1?Q?Tr=E9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , Thibaut Sautereau , Vincent Strubel , linux-kernel , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, LSM List , Linux FS Devel Subject: How about just O_EXEC? (was Re: [PATCH v5 3/6] fs: Enable to enforce noexec mounts or file exec through O_MAYEXEC) Message-ID: <202005142343.D580850@keescook> References: <20200505153156.925111-1-mic@digikod.net> <20200505153156.925111-4-mic@digikod.net> <202005131525.D08BFB3@keescook> <202005132002.91B8B63@keescook> <202005140830.2475344F86@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 14, 2020 at 09:16:13PM +0200, Micka?l Sala?n wrote: > On 14/05/2020 18:10, Stephen Smalley wrote: > > On Thu, May 14, 2020 at 11:45 AM Kees Cook wrote: > >> So, it looks like adding FMODE_EXEC into f_flags in do_open() is needed in > >> addition to injecting MAY_EXEC into acc_mode in do_open()? Hmmm > > > > Just do both in build_open_flags() and be done with it? Looks like he > > was already setting FMODE_EXEC in patch 1 so we just need to teach > > AppArmor/TOMOYO to check for it and perform file execute checking in > > that case if !current->in_execve? > > I can postpone the file permission check for another series to make this > one simpler (i.e. mount noexec only). Because it depends on the sysctl > setting, it is OK to add this check later, if needed. In the meantime, > AppArmor and Tomoyo could be getting ready for this. So, after playing around with this series, investigating Stephen's comments, digging through the existing FMODE_EXEC uses, and spending a bit more time thinking about Lev and Aleksa's dislike of the sysctls, I've got a much more radically simplified solution that I think could work. Maybe I've missed some earlier discussion that ruled this out, but I couldn't find it: let's just add O_EXEC and be done with it. It actually makes the execve() path more like openat2() and is much cleaner after a little refactoring. Here are the results, though I haven't emailed it yet since I still want to do some more testing: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=kspp/o_exec/v1 I look forward to flames! ;) -- Kees Cook