Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2463982ybk; Sun, 17 May 2020 22:58:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0Q8Y8d54pimZknoefDzfGUXfsHGLyXhsia43SN7PaoMpk+p+62rZFXt8Mt8zFrFRr9732 X-Received: by 2002:a17:906:a441:: with SMTP id cb1mr13131643ejb.45.1589781486115; Sun, 17 May 2020 22:58:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589781486; cv=none; d=google.com; s=arc-20160816; b=vEOOdBprUXrJMAC9NeI9xmnEPXypM7vFhrDT3afPCi2PbiBlC7vtY8tUIcqBp1MMl0 UdsdP5JhvyKEHQs8HASTC6O/c+dd213Dv1Y6ip1zoptnGnkxnxoAClpd62AKrtzN7Yar M1DBx9nuRLLIo+SAG9U9VMsJG0YzW+h2pgn7WwFwmo/FmjERB7mWoAIl1dlY2Ah/aiVw vPc8cTui6jAryhyQSFhBdkt+NbFOiG138rciVSwUpIgb//x/CdE2tGNuxuDnkcH74DjB V+IGj4ZVtF4LXpNZwIU5SsoeH+TWYxFSBDwtxZ0fiIv+JvPGW2ghKcePVr9SgMacIFOt +Dlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XV8qUKmPjPOnYpALDdM3pvEx9LC9/D7hmFTEiazZWxM=; b=cWS1GdSlxI0b6mwtxMy/v8lZ2AOI747QvhgQf3h5dvxXZdEHguXdFonkFIaBO1qt79 HxGJ6PtgeqafTFTkQ8W7/GG8Qkoj/oTBioD2dzt+JuP14qjO4jbkjxuaITNag1sQrlTl f81p7UskY6e1SJfgqPU3oq5rwfX2suSP6LasDvZAHGHTj/Bf6Jnpoud+LELjEaEF2265 hSXV8E8tLYcrffbXiM0ns8Fz3hWkv5t9/Plz4OPAoBNlAIdsxkR/j1879fL358cg8YV7 JU35fNYNyqHrL85rCT2DqobpEm6JuoIrqSKsul3oZcjHozZvararIrbv5Jjcqlydo/rQ mfPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lSJ7AfkV; 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 pw5si5529667ejb.354.2020.05.17.22.57.43; Sun, 17 May 2020 22:58:06 -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=lSJ7AfkV; 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 S1726729AbgERFzG (ORCPT + 99 others); Mon, 18 May 2020 01:55:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726478AbgERFzF (ORCPT ); Mon, 18 May 2020 01:55:05 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4478BC05BD0D for ; Sun, 17 May 2020 22:55:05 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id u35so4313519pgk.6 for ; Sun, 17 May 2020 22:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XV8qUKmPjPOnYpALDdM3pvEx9LC9/D7hmFTEiazZWxM=; b=lSJ7AfkVTX/INK1Va1FrJ2kRFSu0fwD/uapRFZ9DRii0sw6g+NoXZWHhKtBbWpBcE5 0cLn8ZEEnWXC5gy/csZhcuB1SVSxhXahc11dUroiH8AJmGVzNsYsk2QjmIm4N/cI1gfm StZfWJtCQfcN+Z1gF/FJEU19a8a30PEC1YQEA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XV8qUKmPjPOnYpALDdM3pvEx9LC9/D7hmFTEiazZWxM=; b=AZUIKZoyQdIqLrrrnJrX2207jMu6hpRlVKFwsFY6f65plkJh7V9dK45Zj37rNfB7b8 nqu4oawoH9W60K9H8D3tmcMIo1dA/dKORTkoOAw/+ZVaN8G53ufGeiz7RPptCXZ3LCkP JzFsPhJor6LDhrjOUVUkhU/6Ao8DMm3Sk2l1CbX+H6wcmgJx77A0+f+ITDAIGgUPcQNo dz3Tt1huLh+mGJ9ZjnkJ0kIHWuzRfKky+SFkV45Hfc6dck0ubo7X23h70v3NOMpC4RC/ 31YwcVxv0uxj90k/hAfsWcmhjBb75WtesVQ320ZfbtxvYyPTl4LkvJmtA43g7yd6S7tX DaVQ== X-Gm-Message-State: AOAM531fDQIlh0S6TtiSoSCPSYaoCJUmPO+Wf9ty53UZtioRGXhMSXRA llC5x4hjxNwLSZJX0lPzvO1/Pw== X-Received: by 2002:a62:29c3:: with SMTP id p186mr15271317pfp.237.1589781304828; Sun, 17 May 2020 22:55:04 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x66sm7653474pfb.173.2020.05.17.22.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 22:55:03 -0700 (PDT) From: Kees Cook To: Al Viro Cc: Kees Cook , 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: [PATCH 4/4] fs: Include FMODE_EXEC when converting flags to f_mode Date: Sun, 17 May 2020 22:54:57 -0700 Message-Id: <20200518055457.12302-5-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200518055457.12302-1-keescook@chromium.org> References: <20200518055457.12302-1-keescook@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Include FMODE_EXEC when building the f_mode field, so that code can actually test the correct field and values. Only three places actually examine f_flags for FMODE_EXEC: fs/open.c: if (unlikely((f->f_mode & FMODE_EXEC) && !S_ISREG(inode->i_mode))) { include/linux/fsnotify.h: if (file->f_mode & FMODE_EXEC) { include/linux/fsnotify.h: if (file->f_mode & FMODE_EXEC) Signed-off-by: Kees Cook --- I assume there must be some reason for FMODE_EXEC not being pulled into f_mode, but I couldn't find it. I guess this is my attempt to either fix an oversight or to learn by flames. :) --- fs/namei.c | 4 ++-- include/linux/fs.h | 3 ++- include/linux/fsnotify.h | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 6bb1b6624bad..362b1cc75f5c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3213,8 +3213,8 @@ static int do_open(struct nameidata *nd, return -ENOTDIR; /* Opening for execution requires a regular file on an exec mnt. */ - if ((file->f_flags & FMODE_EXEC) && (!d_is_reg(nd->path.dentry) || - path_noexec(&nd->path))) + if ((file->f_mode & FMODE_EXEC) && (!d_is_reg(nd->path.dentry) || + path_noexec(&nd->path))) return -EACCES; do_truncate = false; diff --git a/include/linux/fs.h b/include/linux/fs.h index 4f6f59b4f22a..8a2cabdcf531 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3545,10 +3545,11 @@ int __init get_filesystem_list(char *buf); #define __FMODE_EXEC ((__force int) FMODE_EXEC) #define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY) +#define __SMUGGLED_FMODE_FLAGS (__FMODE_EXEC | __FMODE_NONOTIFY) #define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE]) #define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \ - (flag & __FMODE_NONOTIFY))) + (flag & __SMUGGLED_FMODE_FLAGS))) static inline bool is_sxid(umode_t mode) { diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 5ab28f6c7d26..86761ed4b434 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -90,7 +90,7 @@ static inline int fsnotify_perm(struct file *file, int mask) if (mask & MAY_OPEN) { fsnotify_mask = FS_OPEN_PERM; - if (file->f_flags & __FMODE_EXEC) { + if (file->f_mode & FMODE_EXEC) { ret = fsnotify_file(file, FS_OPEN_EXEC_PERM); if (ret) @@ -264,7 +264,7 @@ static inline void fsnotify_open(struct file *file) { __u32 mask = FS_OPEN; - if (file->f_flags & __FMODE_EXEC) + if (file->f_mode & FMODE_EXEC) mask |= FS_OPEN_EXEC; fsnotify_file(file, mask); -- 2.20.1