From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66AB6C433DF for ; Thu, 14 May 2020 14:41:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43198205CB for ; Thu, 14 May 2020 14:41:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="X+1M/fmb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727082AbgENOlo (ORCPT ); Thu, 14 May 2020 10:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726176AbgENOlo (ORCPT ); Thu, 14 May 2020 10:41: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 3D06AC061A0F for ; Thu, 14 May 2020 07:41:44 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id a5so12627754pjh.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=d5ukMEaDDTlEDvd3rW4d8s4GA0Iu0ryKbR5s5wJ6GGx4lyUlKeimYpcR7BAfEed7YY E7Xa7GdGdwhveLJeiCsYQZaBNgW2DA9EosTCcA6GdH0f7qLKDeo3Ge7XQDZYuXQ7g+fL CDyAeGmfGv+RePOEgTygTy/5/Lsq8Jcb1XcEQw0sNFT8lf/bjKIWioa2P0oOEGo1mah/ QJGfBdtEyh+FQOidLNCob7fbqjHJlTkheBBT3FcD3FnzUzTcEOc4AoGm+xp1bMw03dBp RwFtdbiWbNBp7U3WOMY6bhFzUNIM8ny/InIF/32apYIBYXGLi3nKBb3HbGc2bHS6EAua 1qlw== X-Gm-Message-State: AOAM533ENVf3T757SK+FvUTodCFGzFuH1yuWB25KzZ3LvTBelkurkvu8 Ks8qG1dKa+V+1y43l2kpt66JNA== X-Google-Smtp-Source: ABdhPJw803NLliwJdw3Qk5o4x+XH/SQaDwZsQ2JFMZ1iNHIhcyH1GCLb3+bU8sx5k7WA09KC4Ps+iQ== 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-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@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