Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1384960ybk; Thu, 14 May 2020 07:44:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm34tzilU2uE40PmTavtbOcCrcfqi9Hoq2Wsw7UJOyh3nBK30WFZ0GRa5k28XHwGOdE0TL X-Received: by 2002:a50:c3c2:: with SMTP id i2mr4120146edf.93.1589467451335; Thu, 14 May 2020 07:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589467451; cv=none; d=google.com; s=arc-20160816; b=aQBJ8evNEuI9G6G/vwQ+VhXSu6nseVYftKDHZY2ymlh6Vrbx8+pGkIt+uEcEuEFWyl VblvpLEDoV4TJLcTH3sQUjRW4288uTtEiL2VcEztp1EoV4hzZzg2gikFGtVmwCgPK8ku kYsYA5Mvgc+RuYc20m0vJdH3DLcBxDk1zG20PSZ6bDSQyeGQRi3jlBM71X3VZIsrgTBk 6pVNm0Dx8p9fM/ktj4tjdGyxCyb4838AkQrS7Vk5zpqxk2q+Ww2zrl3GobSwmbJ2qufo 4ydWSz2Z0/o9MWULn6wN7GgTjs8XY0tFlbSbK+3Th9O5F7PLhk/A+yC+WkxhswWK1jv+ GWfg== 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=IpKyFs1yszxKs0lfKzxRyfm8sy/4V4zXUkzdtSdkHLU=; b=wgCkQcnc5Y8HUVbLAfbTJL1YClF88TvKRDmMf1NM4720l5l3xR3Jhodoj53Tx8UwEV Af4Dhvvg62raKL3IG9CEk5Ugr5BdJWkWHVGWoD5beDGeZubzUawzFF1mL0Xb67gKMUEi 7JuV02gdJq1Kjg5aU5WaTq6wFUnYCxSnkGodQpMGIeMnmraICM4OBhpqFpvCMLk76tgv Csg836EDZ6MWvNEXxq80FFuKUzlMIKEbCGzXRkhYWdf5Pm2RmOfY4bPaIpK8+8yV5fsh el14VyY+991TKGlnN9La4pGdwkcQ0iRwg52URnBeqIU7KtCP12qhjWpkZIpdFytRvNQo XQFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="X+1M/fmb"; 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 b5si534219ejk.381.2020.05.14.07.43.48; Thu, 14 May 2020 07:44:11 -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="X+1M/fmb"; 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 S1727122AbgENOlq (ORCPT + 99 others); Thu, 14 May 2020 10:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726582AbgENOlo (ORCPT ); Thu, 14 May 2020 10:41:44 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 489D9C05BD09 for ; Thu, 14 May 2020 07:41:44 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id a5so12627755pjh.2 for ; Thu, 14 May 2020 07:41:44 -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=IpKyFs1yszxKs0lfKzxRyfm8sy/4V4zXUkzdtSdkHLU=; b=X+1M/fmbQRViUiNWq5i8Wnhzf2ZxZWa44EfPqXFdhzGNfFrnMMGFlC9RiMxXJ091Ma NG/CNZqhzV1Qho131HIRtHnMmH2dd1a0u/Lnxs7n0oy487ROOuwOgwTDBO2IRRCDsPb3 hmLh+/ITWKzvGRhNGI8R89GJSU8kqpyPsfmQQ= 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=IpKyFs1yszxKs0lfKzxRyfm8sy/4V4zXUkzdtSdkHLU=; b=j2E+1I7cpo6BceyMZ+3uc9kpE3cZScDhA4zYUOnWjdWEAU+35eeRxyNZiVSMScJtgC AAGua+eZAuZEzIH+BoLQz5DnLg5l2/o3l3CStk2PJyfI9CDdO8uvFnusXN9XPGHPUgem RFXQjnQiQx7BNJvkYFL7Izj0KqBTKpNKFa4CoQmGJbiAHphxa3I374awK/WtctvuCFgz eNYihPPw5814JxCNNutF2g9rvGqwEXK3ae+SxwllyTvR2/gk5t+vsH7Z3l9h10dftady lhIV++hhAdQKR6JPIn/zjZ5u/Xl4e/7a1eSZddX2WRTa4gwAM4A7DOeTRS89o3V5XhMn YgtA== X-Gm-Message-State: AOAM532QrAZnh06kbYheh3LfuuaP6+i6rfkVnNaMw6DVr7k4I12F5u3r kz132TdevkHYn/nP5hsuRcuzzw== X-Received: by 2002:a17:902:b608:: with SMTP id b8mr4282064pls.163.1589467303571; Thu, 14 May 2020 07:41:43 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g10sm2542952pfk.103.2020.05.14.07.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 07:41:41 -0700 (PDT) Date: Thu, 14 May 2020 07:41:40 -0700 From: Kees Cook To: Stephen Smalley Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , linux-kernel , Aleksa Sarai , Alexei Starovoitov , Al Viro , Andy Lutomirski , Christian Heimes , Daniel Borkmann , Deven Bowers , 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?= , Mimi Zohar , Philippe =?iso-8859-1?Q?Tr=E9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , Thibaut Sautereau , Vincent Strubel , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, LSM List , Linux FS Devel Subject: Re: [PATCH v5 3/6] fs: Enable to enforce noexec mounts or file exec through O_MAYEXEC Message-ID: <202005140739.F3A4D8F3@keescook> References: <20200505153156.925111-1-mic@digikod.net> <20200505153156.925111-4-mic@digikod.net> <202005131525.D08BFB3@keescook> <202005132002.91B8B63@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 Thu, May 14, 2020 at 08:22:01AM -0400, Stephen Smalley wrote: > On Wed, May 13, 2020 at 11:05 PM Kees Cook wrote: > > > > On Wed, May 13, 2020 at 04:27:39PM -0700, Kees Cook wrote: > > > Like, couldn't just the entire thing just be: > > > > > > diff --git a/fs/namei.c b/fs/namei.c > > > index a320371899cf..0ab18e19f5da 100644 > > > --- a/fs/namei.c > > > +++ b/fs/namei.c > > > @@ -2849,6 +2849,13 @@ static int may_open(const struct path *path, int acc_mode, int flag) > > > break; > > > } > > > > > > + if (unlikely(mask & MAY_OPENEXEC)) { > > > + if (sysctl_omayexec_enforce & OMAYEXEC_ENFORCE_MOUNT && > > > + path_noexec(path)) > > > + return -EACCES; > > > + if (sysctl_omayexec_enforce & OMAYEXEC_ENFORCE_FILE) > > > + acc_mode |= MAY_EXEC; > > > + } > > > error = inode_permission(inode, MAY_OPEN | acc_mode); > > > if (error) > > > return error; > > > > > > > FYI, I've confirmed this now. Effectively with patch 2 dropped, patch 3 > > reduced to this plus the Kconfig and sysctl changes, the self tests > > pass. > > > > I think this makes things much cleaner and correct. > > I think that covers inode-based security modules but not path-based > ones (they don't implement the inode_permission hook). For those, I > would tentatively guess that we need to make sure FMODE_EXEC is set on > the open file and then they need to check for that in their file_open > hooks. Does there need to be an FMODE_OPENEXEC, or is the presence of FMODE_OPEN with FMODE_EXEC sufficient? -- Kees Cook