Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4483437ybx; Mon, 4 Nov 2019 14:10:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyRJUnlYm/55qztpsBV97Y+WEIXsPG7FuXlw/VhPPfzGBIJ9u8nC3LK3cZ4s2wnEbML7Jwf X-Received: by 2002:a17:906:8697:: with SMTP id g23mr20015730ejx.177.1572905457007; Mon, 04 Nov 2019 14:10:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905457; cv=none; d=google.com; s=arc-20160816; b=bcg4MwyObK1Gn+mmortNL8lO5/jBrW8LLrvN5AxhH5yyuDNHltRALAs9fVwaIDJMvc b12SS+QhYZDdxuF0tD/dKWbuDif/8TBRu/728PIUtDbP+PYzadxAo4Ch/AfEMqbEMBNK 3k2nPSpIHXMe+KR/I/6gxJF4xYFuuesCpc94SVgT450xvvTnjQhLiSGjFYn65MQZ/TvO bugEfyJpw7NmW3bfJ+77kh95+MV56hkJ9pRSgxbWMYClaBe1qqR7A7p11/l3XpI3xW38 c9AWtDWmUmjEnwHZKXRpKW3rTEYLNg0l++serN6KJ9Jb+09olqGGj7PmCeAlM8xThAIT H4zQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=T9zrDQKVwL1EW8qohD/e2cOLQSpQMh3R/AwmGtliM6g=; b=TUB+WeamxTUyTOi11ug7Dd1CrE0I2bPBr0NfDmVNq+GNGyoaOodOA42ZHF0bqlLXJW g6Gu2H8TEoEDrYLrEJBdJ8nM5kyLtKLwuK/GVujfY/3nLYDHTwRKOUQxr/dwyzXiDSMw zHDOKQG3Z8N+SsefJ56RaFPqbYTSMIsBsgy/dro/WJWN/DIBhoEHee6mehJeb0ncwIoK ZMaTjOmS+77Btlgh6r2+7s68S1McBvxP+ld4rWdsj5kSqG7rOuGxGqjmJv5x/tU10odp 4Ki/nc9Dpo0OktpK4V/45XRAm3WntryWCrv7IhpnDivBXtfjKAbCe8lj4LX9A4GNTVwy CUrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cWZqDtQK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20si9822797ejb.302.2019.11.04.14.10.33; Mon, 04 Nov 2019 14:10:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cWZqDtQK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389220AbfKDWKG (ORCPT + 99 others); Mon, 4 Nov 2019 17:10:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:43150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389262AbfKDWJ7 (ORCPT ); Mon, 4 Nov 2019 17:09:59 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 219DE2084D; Mon, 4 Nov 2019 22:09:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905398; bh=hMZ+6uzgHEr/dMaKBuhF6e8kLt6gB4N3Cpnqs0zwZ5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cWZqDtQK8uiiMCQ6Hp28KhIYb8VlYqjF0YjJGUvxc2w9v+rtoiJorS7RODzakZ+fh Gm/VC22xXWWQyEouqrzjX0idHmorSdQ6PY40cTYbketp/EzYxaZSV/i8R1RYtcjakI iG3iUWPsrDuQQsdby5O116tIx9MlIZ1bL7MLiBD4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giuseppe Scrivano , Miklos Szeredi Subject: [PATCH 5.3 095/163] fuse: flush dirty data/metadata before non-truncate setattr Date: Mon, 4 Nov 2019 22:44:45 +0100 Message-Id: <20191104212147.014034079@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miklos Szeredi commit b24e7598db62386a95a3c8b9c75630c5d56fe077 upstream. If writeback cache is enabled, then writes might get reordered with chmod/chown/utimes. The problem with this is that performing the write in the fuse daemon might itself change some of these attributes. In such case the following sequence of operations will result in file ending up with the wrong mode, for example: int fd = open ("suid", O_WRONLY|O_CREAT|O_EXCL); write (fd, "1", 1); fchown (fd, 0, 0); fchmod (fd, 04755); close (fd); This patch fixes this by flushing pending writes before performing chown/chmod/utimes. Reported-by: Giuseppe Scrivano Tested-by: Giuseppe Scrivano Fixes: 4d99ff8f12eb ("fuse: Turn writeback cache on") Cc: # v3.15+ Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dir.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1476,6 +1476,19 @@ int fuse_do_setattr(struct dentry *dentr is_truncate = true; } + /* Flush dirty data/metadata before non-truncate SETATTR */ + if (is_wb && S_ISREG(inode->i_mode) && + attr->ia_valid & + (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_MTIME_SET | + ATTR_TIMES_SET)) { + err = write_inode_now(inode, true); + if (err) + return err; + + fuse_set_nowrite(inode); + fuse_release_nowrite(inode); + } + if (is_truncate) { fuse_set_nowrite(inode); set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);