Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4498369ybx; Mon, 4 Nov 2019 14:24:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxtZ0mNKF1l3D3KPX2EYZgLOb4I/Jve3VHxRjv4DWZQwpJB/b7SshgeZRHEO2AR+MsZh1Ea X-Received: by 2002:a17:906:86d5:: with SMTP id j21mr26014170ejy.219.1572906262420; Mon, 04 Nov 2019 14:24:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572906262; cv=none; d=google.com; s=arc-20160816; b=ybf8hUyM4lvcPd5AO5TW+WeFKJeb0Ik8w1e8BdMjw62+orC71VUn0oyfMqbMTmVw1d WnpTNAUGSlVHXs5ZEAk86kZcWEPJt2YASJVfoNd3i4+dCXjAYdw/IxWSLB+RrGCuL7va TQmv23Keqmcm/JVzviZ1swPmmrLWrt4wRL4O+xo7ibbnF0tGcti0LRdkYgHHvfa1AL1r SMhKuvjJlaixunZC89IVhgtuhG+WLeYLncnnLQ6c99b2BUpTklsKX1A1Gze9rSQHOb8X KoO15UAalLJa/MfXms7pP91u9odwDywrCvaBE441wRsig0O3jbUloPb0x9oxOPLhILeP KmoQ== 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=HRLQqNcdTWJDVaIbsH/KbnCp3cITySok8OHu4Qs3+WY=; b=RgyNfad66gHwA+W3aYvZ51T+t5yZe5gx9Fr7doQxWKQFZcMy/J+ur+Uip/bjbvcag+ lXsQ0QM6SYYivpwzsgR4wkoXpN7zSKEUIgQymmH8TPVIocOygjFOi+5ZmnI/0sij6+fT alL+78yeW/xh2J5h4vADD3+7IVycAfpDcajTU7ngcDnGYynnORsNX2j+kVByecvJkpXC hskOXYwLOgvR2Sjs6NRJBbHZpjMIBNLDJPnh8MhWkB2wHokK7B/oKIa1kIlm8sxW6yPq YSSHDEfKCrnv52Ui1uWPBhbuCTsvLo1PqPJVJ3bMZIKoQpEEhhH227CdwA8RfXR207OP fMvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KluvRJ1J; 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 p22si10951536eja.204.2019.11.04.14.23.53; Mon, 04 Nov 2019 14:24:22 -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=KluvRJ1J; 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 S2388763AbfKDWXK (ORCPT + 99 others); Mon, 4 Nov 2019 17:23:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:49648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388005AbfKDVyo (ORCPT ); Mon, 4 Nov 2019 16:54:44 -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 A5246217F4; Mon, 4 Nov 2019 21:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904483; bh=otbvzpKXSznWyES7ADq4XyeZ2E1UOjUoRZ6d2UkJ+hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KluvRJ1Jn/PEWVfJThzWX52jbnlNPn5HKAHvmFzwYEbwGIR3HuRrRijGzm70i4WId nwSQfX/X64ToiGIhJpmuWAe4iiNsZJmWLqdBsLv3/groA77S7/oMQbnblDY8eBOjGo dEd9z7MxUMJXq8h2zUHS8gD0xAWONRS7B/h+SEgI= 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.14 62/95] fuse: flush dirty data/metadata before non-truncate setattr Date: Mon, 4 Nov 2019 22:45:00 +0100 Message-Id: <20191104212108.324452324@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212038.056365853@linuxfoundation.org> References: <20191104212038.056365853@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 @@ -1650,6 +1650,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);