Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2171014ybm; Thu, 23 May 2019 12:31:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqLhSAa5ULXBdjikpip9ABJ4/ixe33Pdho3aYZefcNFru3OlNMPQYTvFjf264sBdI87VdB X-Received: by 2002:a62:386:: with SMTP id 128mr81572585pfd.10.1558639899962; Thu, 23 May 2019 12:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558639899; cv=none; d=google.com; s=arc-20160816; b=pzTpnQx8eQSiT+GzwMXWrd6f2n+bckpqrUANiKKLLoINVPo7ZVf0MJ4Q1Tjc0K+RGE up5NFDf3S4mZLNS/zHR/FkAeKbE6iK6/jXmFrnw/xgcBzxwnUy8AJ2GuCUbJ8dFqn3j1 zHSTVFu8mMOOECA5SLEIfhHmFo1EDgoN0FV+b2tfNcadjcm/37Sumo7fltc0pHap/0P9 lDaALFwYEtFmCS1BlPX0oMdUXOfvVJZBS6CUa5n/LVqQOA6Weod2Z+RijFfq0WjI+3ml BEwC+AYd2NiTI7q9T7X3ZBChKusWBHYOA0cIro1nRGFpSgk/CeN1NnPcVdwQIzGC+OM/ TnFA== 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=kB/tDdPjxH/4CtlpwHf38t6dik7SXCPMQguxo7Qe6eM=; b=wOg0Ex8fRugVgBsgIDFcjZI+cIxbliJXbKxUjllClsicY+p6yIXtN09xK4+ypOEDp4 KTL6EHbOR3ssCGBnpRhC3zocs/acPNyabn9p7smAI1MFsHOYOwikiEW2wumPUb5DVI1X BCkfIXy9AsHfMWR7STyIkB+l3MAQJrHQOYbATorb9EVTkXSf6fsA2bhV+UxqozXE86tD JYTsEB7ejXaI/CctJEwsIfbtKpJoRxA6T92Ehh+av4l5NyXOmhZKaINF2ydUCRTVT3he VIMy1E198PN3ECxoPB7m73wO1IQZDdCXYbujo36WgcTIMbgQGibnywAgnYmXlsQLymXk U6lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uM8iDsBt; 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 bh11si353098plb.383.2019.05.23.12.31.24; Thu, 23 May 2019 12:31:39 -0700 (PDT) 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=uM8iDsBt; 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 S2391653AbfEWT3V (ORCPT + 99 others); Thu, 23 May 2019 15:29:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:42368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391649AbfEWT3T (ORCPT ); Thu, 23 May 2019 15:29:19 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 576D5217D9; Thu, 23 May 2019 19:29:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639758; bh=6w0XLcK3kA/Yt7EYerfmqZO1sv5gIWUrf5GK4rnJhIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uM8iDsBtIMYjltW3ricV2+QS1C3y9AxH4n2DbsYWAolP0r/aVSJ+nQ35noUOmXDYo KjNSGERa5+7fYTZTUvE3vmixhLYc3oPjnQOpGkSt6hTWRaY4HoGpmd3orC7rPgscTU Nt/oBminEc+f45Cmxey/hzJaN24jZ4rWetZT/s9k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Amir Goldstein , Vivek Goyal , Miklos Szeredi Subject: [PATCH 5.1 068/122] ovl: fix missing upper fs freeze protection on copy up for ioctl Date: Thu, 23 May 2019 21:06:30 +0200 Message-Id: <20190523181713.725802237@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181705.091418060@linuxfoundation.org> References: <20190523181705.091418060@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: Amir Goldstein commit 3428030da004a1128cbdcf93dc03e16f184d845b upstream. Generalize the helper ovl_open_maybe_copy_up() and use it to copy up file with data before FS_IOC_SETFLAGS ioctl. The FS_IOC_SETFLAGS ioctl is a bit of an odd ball in vfs, which probably caused the confusion. File may be open O_RDONLY, but ioctl modifies the file. VFS does not call mnt_want_write_file() nor lock inode mutex, but fs-specific code for FS_IOC_SETFLAGS does. So ovl_ioctl() calls mnt_want_write_file() for the overlay file, and fs-specific code calls mnt_want_write_file() for upper fs file, but there was no call for ovl_want_write() for copy up duration which prevents overlayfs from copying up on a frozen upper fs. Fixes: dab5ca8fd9dd ("ovl: add lsattr/chattr support") Cc: # v4.19 Signed-off-by: Amir Goldstein Acked-by: Vivek Goyal Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/overlayfs/copy_up.c | 6 +++--- fs/overlayfs/file.c | 5 ++--- fs/overlayfs/overlayfs.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -909,14 +909,14 @@ static bool ovl_open_need_copy_up(struct return true; } -int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags) +int ovl_maybe_copy_up(struct dentry *dentry, int flags) { int err = 0; - if (ovl_open_need_copy_up(dentry, file_flags)) { + if (ovl_open_need_copy_up(dentry, flags)) { err = ovl_want_write(dentry); if (!err) { - err = ovl_copy_up_flags(dentry, file_flags); + err = ovl_copy_up_flags(dentry, flags); ovl_drop_write(dentry); } } --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -116,11 +116,10 @@ static int ovl_real_fdget(const struct f static int ovl_open(struct inode *inode, struct file *file) { - struct dentry *dentry = file_dentry(file); struct file *realfile; int err; - err = ovl_open_maybe_copy_up(dentry, file->f_flags); + err = ovl_maybe_copy_up(file_dentry(file), file->f_flags); if (err) return err; @@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, if (ret) return ret; - ret = ovl_copy_up_with_data(file_dentry(file)); + ret = ovl_maybe_copy_up(file_dentry(file), O_WRONLY); if (!ret) { ret = ovl_real_ioctl(file, cmd, arg); --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -421,7 +421,7 @@ extern const struct file_operations ovl_ int ovl_copy_up(struct dentry *dentry); int ovl_copy_up_with_data(struct dentry *dentry); int ovl_copy_up_flags(struct dentry *dentry, int flags); -int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags); +int ovl_maybe_copy_up(struct dentry *dentry, int flags); int ovl_copy_xattr(struct dentry *old, struct dentry *new); int ovl_set_attr(struct dentry *upper, struct kstat *stat); struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper);