From patchwork Thu Feb 27 21:11:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11410053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E854138D for ; Thu, 27 Feb 2020 21:29:04 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 772F8246A1 for ; Thu, 27 Feb 2020 21:29:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 772F8246A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 9B04A348C21; Thu, 27 Feb 2020 13:25:09 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 88A9E21FCD2 for ; Thu, 27 Feb 2020 13:19:26 -0800 (PST) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id E9AC92C52; Thu, 27 Feb 2020 16:18:15 -0500 (EST) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id E859A46D; Thu, 27 Feb 2020 16:18:15 -0500 (EST) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 27 Feb 2020 16:11:32 -0500 Message-Id: <1582838290-17243-225-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> References: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 224/622] lustre: llite: Lock inode on tiny write if setuid/setgid set X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ann Koehler , Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Ann Koehler During a write, the setuid/setgid bits must be reset if they are enabled and the user does not have the correct permissions. Setting any file attributes, including setuid and setgid, requires the inode to be locked. Writes became lockless with the introduction of LU-1669. Locking the inode in the setuid/setgid case was added to vvp_io_write_start() as a special case. The inode locking was not included when support for tiny writes was added with LU-9409. This mod adds the necessary inode lock/unlock calls to ll_do_tiny_write(). If the inode is not locked when setuid/setgid are reset, the kernel will issue a one time warning and Lustre may hang trying to get the inode lock in ll_setattr_raw(). WC-bug-id: https://jira.whamcloud.com/browse/LU-11944 Lustre-commit: f39a552922ca ("LU-11944 llite: Lock inode on tiny write if setuid/setgid set") Signed-off-by: Ann Koehler Reviewed-on: https://review.whamcloud.com/34218 Reviewed-by: Patrick Farrell Reviewed-by: Ben Evans Reviewed-by: James Simmons Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- fs/lustre/llite/file.c | 6 ++++++ fs/lustre/llite/vvp_io.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/lustre/llite/file.c b/fs/lustre/llite/file.c index 7078734..a73d11f 100644 --- a/fs/lustre/llite/file.c +++ b/fs/lustre/llite/file.c @@ -1616,6 +1616,7 @@ static ssize_t ll_do_tiny_write(struct kiocb *iocb, struct iov_iter *iter) ssize_t count = iov_iter_count(iter); struct file *file = iocb->ki_filp; struct inode *inode = file_inode(file); + bool lock_inode = !IS_NOSEC(inode); ssize_t result = 0; /* Restrict writes to single page and < PAGE_SIZE. See comment at top @@ -1625,8 +1626,13 @@ static ssize_t ll_do_tiny_write(struct kiocb *iocb, struct iov_iter *iter) (iocb->ki_pos & (PAGE_SIZE-1)) + count > PAGE_SIZE) return 0; + if (unlikely(lock_inode)) + inode_lock(inode); result = __generic_file_write_iter(iocb, iter); + if (unlikely(lock_inode)) + inode_unlock(inode); + /* If the page is not already dirty, ll_tiny_write_begin returns * -ENODATA. We continue on to normal write. */ diff --git a/fs/lustre/llite/vvp_io.c b/fs/lustre/llite/vvp_io.c index 85bb3e0..ad4b39e 100644 --- a/fs/lustre/llite/vvp_io.c +++ b/fs/lustre/llite/vvp_io.c @@ -1037,13 +1037,13 @@ static int vvp_io_write_start(const struct lu_env *env, * consistency, proper locking to protect against writes, * trucates, etc. is handled in the higher layers of lustre. */ - bool lock_node = !IS_NOSEC(inode); + lock_inode = !IS_NOSEC(inode); - if (lock_node) + if (unlikely(lock_inode)) inode_lock(inode); result = __generic_file_write_iter(vio->vui_iocb, vio->vui_iter); - if (lock_node) + if (unlikely(lock_inode)) inode_unlock(inode); if (result > 0 || result == -EIOCBQUEUED)