Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1429367ybk; Thu, 14 May 2020 08:47:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLOu+wfg9CtJ2n7H6fj4ZiIdfGrT8Dp2+VxUZEu269oBbIwG0K6hdjz99DB590KoDIroR7 X-Received: by 2002:a50:dac4:: with SMTP id s4mr4331533edj.277.1589471240999; Thu, 14 May 2020 08:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589471240; cv=none; d=google.com; s=arc-20160816; b=H2dOAtvzbscHh3YlGVscgwg9/forV+SHC7GoWb8y9qut3GDVhVvMjxNHZhsWd5Xo8a bWkqOjbYZuaOn4b+7e3+arxYbYOLKdBLttytm6WqXjMCIai/HkH7gkrEQ/5rs4EBjVqH cuV4jeqOVqDlkubv1VUZuke5xRK6vu0JgKIJUlmtkyUmV7ZHat5+nVmUhrUJD0z37o05 xswWUBTGXiqON4mPTPcfDH9d3sp6Yok0WwfUSgx72q8yaoTkBlFrJO/DIPA++sHgH7mq PCUBzrabAjeuy9J9Q4XceMVt/+UWO7sAOwb7j9wMRSovI/xnMd2ZZBqrCxcCuWshniF3 dT/A== 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=C14dFYivD8qv8BpAvB7kTDBgmObt0Bwj81tS0Zc4/E8=; b=Ee0hQYgY3T+J7fsr6ULIgJpU424ss8Lmo2+kxx4oQOGwcmvPl8YoOvTqecc12TahwQ 34HVI9/SsqoZZ926e0v109RljNQjwbwwarudptuFjFaqvv3q1W/4oLfOy1e4CqomYX36 YwHY4SpWe3/REuyAb52SxsXqrvqbQN214s7SxXhOg2SrRU8t13vr2/qMjGxKhfbv9RDY igNKMuv8NltpIRXfTUTA0qaSXHHsD2dqi9WmRGlsSeWflsPzPtvzVPE92SIYB0wkbk40 ofp4pOO7fy4RicaPG3dAuP91y01W6I8lopB8EYeYw0uhlsbVakeroGbCw/FKmAg4/P8i BxJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WeBSVMSY; 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 w13si2173013edf.228.2020.05.14.08.46.57; Thu, 14 May 2020 08:47:20 -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=WeBSVMSY; 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 S1727790AbgENPpT (ORCPT + 99 others); Thu, 14 May 2020 11:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726551AbgENPpR (ORCPT ); Thu, 14 May 2020 11:45:17 -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 21A5BC05BD09 for ; Thu, 14 May 2020 08:45:16 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id ms17so12619067pjb.0 for ; Thu, 14 May 2020 08:45:16 -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=C14dFYivD8qv8BpAvB7kTDBgmObt0Bwj81tS0Zc4/E8=; b=WeBSVMSYQ4gtB5dULeEkKU/Ya0fz/EW/RpuUt7D8OeJEBKAKV2pF5kPidP02iOR39J G1MttEPeItqlTkRXkO6DaVmCrP7nH7+PO7my0CuD5d86lDI5xv46HrYCZiFQuNjdOnTz 5lq27uwgV1aYUO8FPK6JNzqOwNdl1+mzKbYGk= 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=C14dFYivD8qv8BpAvB7kTDBgmObt0Bwj81tS0Zc4/E8=; b=oHYCSu7tnBLIk7FBuwrMbW/4ElJI/b9tNRaAWSAWdsG0NYh2YH/7MSx2z0VRPuFguH iKAPeu2c3gmfj/cutFevmoDAvpeNpFOMxCkCXtPLhSXRaECAb3hssRrcBCtz9R6LCFw2 MhC/8LP5PP4vGlStNDB7sRWIjVu6ujrEo0fo45KJI3nGpolQ4O21Vm/jDjW8OPUj2aX9 oLypAEEjGocjMWyJkDBZ2TK0MekiYwE+PWUyg34tGlEQ5AJK2aVgzOqDaQBOAMzminzE 3aBP59IFscgHJOb0LadCwW0gDxzCWdrIkpKiskTwOQCuGvLiabU32W6/Iyb+PP6YzW/M Izsw== X-Gm-Message-State: AOAM530UAn8ugjQjjmmQ6GaXxUUziAbgdsZIrQSb20e40TTRASytYqzr U8gKUjG8rynhmWxw/heu4pzk+A== X-Received: by 2002:a17:902:c113:: with SMTP id 19mr4514772pli.95.1589471115414; Thu, 14 May 2020 08:45:15 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e15sm1909094pfh.23.2020.05.14.08.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 08:45:14 -0700 (PDT) Date: Thu, 14 May 2020 08:45:13 -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: <202005140830.2475344F86@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. I kept confusing myself about what order things happened in, so I made these handy notes about the call graph: openat2(dfd, char * filename, open_how) do_filp_open(dfd, filename, open_flags) path_openat(nameidata, open_flags, flags) do_open(nameidata, file, open_flags) may_open(path, acc_mode, open_flag) inode_permission(inode, MAY_OPEN | acc_mode) security_inode_permission(inode, acc_mode) vfs_open(path, file) do_dentry_open(file, path->dentry->d_inode, open) if (unlikely(f->f_flags & FMODE_EXEC && !S_ISREG(inode->i_mode))) ... security_file_open(f) open() 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 -- Kees Cook