Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4502852ybx; Mon, 4 Nov 2019 14:28:27 -0800 (PST) X-Google-Smtp-Source: APXvYqwljC/CshV3UugZWmYWz1VFF5pIYqjYkG6wqbThuhktSHoeMF0AalT7mQAaKSqVLWHZAYUI X-Received: by 2002:a17:906:7e41:: with SMTP id z1mr19134831ejr.63.1572906507096; Mon, 04 Nov 2019 14:28:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572906507; cv=none; d=google.com; s=arc-20160816; b=oNoA5IzIkGLM/XQiu8XGR7IdgyFekHWPAUJCoTMvYUIai8r9J9Y9FyuCAWvXvZa9gm dZRPCuv0ZZxl4MZd4I91JKopMF32wLcOCu/JmS/bobL3+b+HHiaiE3vz5ckAflGDHEr6 nuOXyzKcD0Q8M1CiSl0EwxBpd9jA/Q2ShkX30G7hQmPEt1gR4Fi7t4qz4Nuocctbs9/4 um4l9Kc5vLiXEqSGY3wGaTOD5P8AMvNd4hSZ9plRqwDXifFb5V0BcaVPLtf3rmkBG7J0 JZDEquhnaoi2hQsilGjw3GVhOuSD9wQZs5R5yg60JVM1tWxaxHOahLto+64uFvUmCxqZ Hs9A== 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=hxHHwtmGosb9xntogRqN8xYILrSPF6LW+BL4jx5Wtas=; b=SHoXpXRDVbIoGnVS0UiGiV7JoJeWgWiNQ87+NV6ZZeJj0IN6RUG7hV/1rzZs94NIno UPXosXBKmOwCAdiZSCOhhOikAS0QSp5aDTCRrWZWrMbO6KUal/edqafrnrmmF5wytZ7n WGuNJ0q2ITIl9uZmmyX9a8+i2MpYO2w3ekj+Jzl6lPtklCgVObjUQqkr3fMiQ8aeoX4w i9peL9gMtXLDS3hxruLQ2oXg2Y+LHAi5eE42RemghXnU8ZNOWmcXSfjnNqDECatVJ7l5 T9kuWd42qQkv2SxYHL7+0BYzeQmcXoNJ43pzspdugQRzdkgmiVeeguG7++7h2UjjU7bt t78A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s1S8ccrM; 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 jz21si11468492ejb.422.2019.11.04.14.28.03; Mon, 04 Nov 2019 14:28:27 -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=s1S8ccrM; 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 S2387786AbfKDVun (ORCPT + 99 others); Mon, 4 Nov 2019 16:50:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:43078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387777AbfKDVul (ORCPT ); Mon, 4 Nov 2019 16:50:41 -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 13FBC214D8; Mon, 4 Nov 2019 21:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904240; bh=LfTO+FHeZ6M9Pa2Fk/8x9G7IzL6obf8rE6hsYroN2dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s1S8ccrM6yMfiJSJgfmFicxe/pjrmRYul82g+9J09etFHZFgnI90dZq8IQKV4AHZ+ 1WIUz5qHHTH/vX1jxOOrS3Ggjmn6kz57OVYQ4Bck172mQjAHlmVClzMHjk8bYUXmjW 1LpUYtc4fY3incVuulzEN2AJ8C5jHET+N6vYIz4s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giuseppe Scrivano , Miklos Szeredi Subject: [PATCH 4.9 34/62] fuse: flush dirty data/metadata before non-truncate setattr Date: Mon, 4 Nov 2019 22:44:56 +0100 Message-Id: <20191104211937.303094666@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104211901.387893698@linuxfoundation.org> References: <20191104211901.387893698@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 @@ -1654,6 +1654,19 @@ int fuse_do_setattr(struct dentry *dentr if (attr->ia_valid & ATTR_SIZE) 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);