From patchwork Wed Jan 17 05:44:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10168531 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 499EA601E7 for ; Wed, 17 Jan 2018 05:46:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A9AC27C0B for ; Wed, 17 Jan 2018 05:46:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EF2127F8E; Wed, 17 Jan 2018 05:46:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE9F427C0B for ; Wed, 17 Jan 2018 05:46:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751090AbeAQFqS (ORCPT ); Wed, 17 Jan 2018 00:46:18 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:44093 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750868AbeAQFqR (ORCPT ); Wed, 17 Jan 2018 00:46:17 -0500 Received: by mail-pf0-f194.google.com with SMTP id m26so10973989pfj.11 for ; Tue, 16 Jan 2018 21:46:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=K+zgUAD/ahyyYO7bC1WB5TFt6HyX3lr9HjjMLcaCOyw=; b=JNacyjmLgEfPsUAaGW91WbditVozuQtNndDaSEvnd4nDhGLy0UDTV6Bb/h5RgF2Zl6 qhqWEhvUvDFA1PFHuYxKhyPc9wa8sXm2F4xXiFUyF89ro8jY4Y5N4KQkBnE432SsuUpB ySaFzRXteg29WuoV2Vo2+ou28bBdaKFs0lClWVU4BoKYh/4+zjmjfMGdgD5yko6eLTZQ jt8DH4cjGNDOPnsH1iIFho4Clm6AXedH05Pf7WoDtyhea4ebKLs68Pan77CR/+8ph0LX B6eH/+xjOjDBcYN1V3HP8c0qk1K6+GaXwaEDFDhSGXhqwseGAxlLHGXmpQ9A2J2S7yVx c98g== 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; bh=K+zgUAD/ahyyYO7bC1WB5TFt6HyX3lr9HjjMLcaCOyw=; b=S0W8AiA4/rPVAs5ctWsi6tAgnvHWgzSkxRSpuiiPRTg0Vs0j3K2MGuM3SenV6ZUDur aAXR+gtkbzaFr22tO6BRtFGRqqKPFemO/fb2XnlKojLgib1buxGuBjCSpetZYg1FeYvH Ejy73y+EsYqmswAziAUmPgG5adIBqvdXuG6RuL2RwJWrJY8RBHvVqPoO5zb4nXpC5G3X XYfbfW4oG1sZty2FmUfuTMXIRCw4emJ9gGxND+dwwFR83VzNER4NoZeLoJuPz9Jq60v4 2Wl7hn68cjDzsbgC9l0s2z2VswjAYZnYqJnjGmOQpwDFUbCmUWAK50ej88CtH3GW+mUi 5c0Q== X-Gm-Message-State: AKGB3mIt++g2MYoIEnjDC0DIx8Aj1ZYNoTokJXAPTYSyZ+85vEnN7uOD 2epyrYp4g1yWOXPlTciMbJEC85uO X-Google-Smtp-Source: ACJfBouljaoDMl8cA9C8qc1AWhu2llMtYwMku1KPx682DVropMO4/yaV5sfwgRsawrtjbfXrhNhnJQ== X-Received: by 10.99.157.13 with SMTP id i13mr33105930pgd.309.1516167976555; Tue, 16 Jan 2018 21:46:16 -0800 (PST) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id b6sm6592045pfc.139.2018.01.16.21.46.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 21:46:16 -0800 (PST) From: Eric Biggers To: linux-fsdevel@vger.kernel.org, Alexander Viro Cc: Miklos Szeredi , Eric Biggers Subject: [PATCH] fs: fold __inode_permission() into inode_permission() Date: Tue, 16 Jan 2018 21:44:24 -0800 Message-Id: <20180117054424.16353-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.1 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Since commit 9c630ebefeee ("ovl: simplify permission checking"), overlayfs doesn't call __inode_permission() anymore, which leaves no users other than inode_permission(). So just fold it back into inode_permission(). Signed-off-by: Eric Biggers --- fs/namei.c | 71 ++++++++++++++++++++---------------------------------- include/linux/fs.h | 1 - 2 files changed, 26 insertions(+), 46 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 7c221fb0836b..921ae32dbc80 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -390,50 +390,6 @@ static inline int do_inode_permission(struct inode *inode, int mask) return generic_permission(inode, mask); } -/** - * __inode_permission - Check for access rights to a given inode - * @inode: Inode to check permission on - * @mask: Right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC) - * - * Check for read/write/execute permissions on an inode. - * - * When checking for MAY_APPEND, MAY_WRITE must also be set in @mask. - * - * This does not check for a read-only file system. You probably want - * inode_permission(). - */ -int __inode_permission(struct inode *inode, int mask) -{ - int retval; - - if (unlikely(mask & MAY_WRITE)) { - /* - * Nobody gets write access to an immutable file. - */ - if (IS_IMMUTABLE(inode)) - return -EPERM; - - /* - * Updating mtime will likely cause i_uid and i_gid to be - * written back improperly if their true value is unknown - * to the vfs. - */ - if (HAS_UNMAPPED_ID(inode)) - return -EACCES; - } - - retval = do_inode_permission(inode, mask); - if (retval) - return retval; - - retval = devcgroup_inode_permission(inode, mask); - if (retval) - return retval; - - return security_inode_permission(inode, mask); -} -EXPORT_SYMBOL(__inode_permission); - /** * sb_permission - Check superblock-level permissions * @sb: Superblock of inode to check permission on @@ -472,7 +428,32 @@ int inode_permission(struct inode *inode, int mask) retval = sb_permission(inode->i_sb, inode, mask); if (retval) return retval; - return __inode_permission(inode, mask); + + if (unlikely(mask & MAY_WRITE)) { + /* + * Nobody gets write access to an immutable file. + */ + if (IS_IMMUTABLE(inode)) + return -EPERM; + + /* + * Updating mtime will likely cause i_uid and i_gid to be + * written back improperly if their true value is unknown + * to the vfs. + */ + if (HAS_UNMAPPED_ID(inode)) + return -EACCES; + } + + retval = do_inode_permission(inode, mask); + if (retval) + return retval; + + retval = devcgroup_inode_permission(inode, mask); + if (retval) + return retval; + + return security_inode_permission(inode, mask); } EXPORT_SYMBOL(inode_permission); diff --git a/include/linux/fs.h b/include/linux/fs.h index 93f058af32de..099a27ad40ca 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2691,7 +2691,6 @@ extern sector_t bmap(struct inode *, sector_t); #endif extern int notify_change(struct dentry *, struct iattr *, struct inode **); extern int inode_permission(struct inode *, int); -extern int __inode_permission(struct inode *, int); extern int generic_permission(struct inode *, int); extern int __check_sticky(struct inode *dir, struct inode *inode);