Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp809908ybl; Wed, 11 Dec 2019 07:51:39 -0800 (PST) X-Google-Smtp-Source: APXvYqwPDyJuc0lo7mhR1QIxu91K60GOQJpybO+jcjvN/S8sDUJ/GuxmhepOczJiddgx8zQeQqOf X-Received: by 2002:a05:6830:18d7:: with SMTP id v23mr2635579ote.213.1576079499794; Wed, 11 Dec 2019 07:51:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079499; cv=none; d=google.com; s=arc-20160816; b=RBGcW++mNAZgrUWi0UX39EeKOnArVR/g/6HJ692iemTlTsyCIm6B79A4yfRxRCq1gJ gYoDsTlOZnM3NVJeGkz0lCKqOtG0wHp0gzHw4seaHO0SNW7fRem4e23Whp5MgoCzASjT 6xKL+BE1b3B9htZSfChaiYXtH7zyJ+z7zy8IqVEfpER32KufF3RrL3K+bflYUVvUPsJx yXgVGuATEKCK5I0Ls2Q2wvXQzeRyWCYcELZURLojW2fVHsQZ8UPrgWoP3hiUVFV8p9Kt Y4iLj97JnaAwvCqr0Ds0vTZQ8+fEhBYFbNqIWdjr95M1pBco7hB9cdEIkuedoVFwDs8m N4Bg== 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=O7MuwlfSNpWV2bFkvbU9I0eg1WW5UlylbyvHSsCGsuU=; b=ADQ129jH5maOmDRV3YFG5J2iWTAcn9t5shmD5+c6g+o9i+woOX8MOX+XSEn1UAsZNt kLGE45FTNusFszEpR460h0zNibMfLXSzIijuFEs9fR768MrqB/CfDIuONzJ2gckj1tnN 5NItMS9akGgwUchwu9iL/w7Fm+vOX4I7d0nD7afcQsxK/8fgsoZNeeqZ+KK97sLl3AqZ 2g5+gEvUy4SxfRrOarpm3aGJZRpukEOf0fbNyArtNi+4+uu5WGSiT9RAnG5dMTPxAPyb lR71l+E1N1Dtph00kJfQFTUIfB61jI+Jc4B/LsdtCAaS2iB/Gwg5hlBK3ff3/zWo3PFF BLFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bXyUy39D; 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 m5si1232472ote.187.2019.12.11.07.51.26; Wed, 11 Dec 2019 07:51:39 -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=bXyUy39D; 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 S1732834AbfLKPYV (ORCPT + 99 others); Wed, 11 Dec 2019 10:24:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:55586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732824AbfLKPYR (ORCPT ); Wed, 11 Dec 2019 10:24:17 -0500 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 895A52173E; Wed, 11 Dec 2019 15:24:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077857; bh=nbZ7fQzT29Io1UH8chLzIhDm13EYvBMWrrF8VxGouZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bXyUy39DSeaSy+LzqsPqGIh8UfNwe/KtNcGFNPZEDbdU0B9QiWAEkZZv8YnS+w1MS +LCFsw4++I74n/TdAcDKeEbAvwQ1rWe3Gc6sZtYnGQz8jhmpVMIkUYQroea4Bjd8Cp 9Eho9Lc5kkHRqtwF5fKA5L9IH++P7jrIpdS6J/pU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arijit Banerjee , Miklos Szeredi Subject: [PATCH 4.19 198/243] fuse: verify attributes Date: Wed, 11 Dec 2019 16:06:00 +0100 Message-Id: <20191211150352.544263323@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@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 eb59bd17d2fa6e5e84fba61a5ebdea984222e6d5 upstream. If a filesystem returns negative inode sizes, future reads on the file were causing the cpu to spin on truncate_pagecache. Create a helper to validate the attributes. This now does two things: - check the file mode - check if the file size fits in i_size without overflowing Reported-by: Arijit Banerjee Fixes: d8a5ba45457e ("[PATCH] FUSE - core") Cc: # v2.6.14 Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dir.c | 24 +++++++++++++++++------- fs/fuse/fuse_i.h | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -234,7 +234,8 @@ static int fuse_dentry_revalidate(struct kfree(forget); if (ret == -ENOMEM) goto out; - if (ret || (outarg.attr.mode ^ inode->i_mode) & S_IFMT) + if (ret || fuse_invalid_attr(&outarg.attr) || + (outarg.attr.mode ^ inode->i_mode) & S_IFMT) goto invalid; forget_all_cached_acls(inode); @@ -297,6 +298,12 @@ int fuse_valid_type(int m) S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m); } +bool fuse_invalid_attr(struct fuse_attr *attr) +{ + return !fuse_valid_type(attr->mode) || + attr->size > LLONG_MAX; +} + int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, struct fuse_entry_out *outarg, struct inode **inode) { @@ -328,7 +335,7 @@ int fuse_lookup_name(struct super_block err = -EIO; if (!outarg->nodeid) goto out_put_forget; - if (!fuse_valid_type(outarg->attr.mode)) + if (fuse_invalid_attr(&outarg->attr)) goto out_put_forget; *inode = fuse_iget(sb, outarg->nodeid, outarg->generation, @@ -451,7 +458,8 @@ static int fuse_create_open(struct inode goto out_free_ff; err = -EIO; - if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid)) + if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid) || + fuse_invalid_attr(&outentry.attr)) goto out_free_ff; ff->fh = outopen.fh; @@ -558,7 +566,7 @@ static int create_new_entry(struct fuse_ goto out_put_forget_req; err = -EIO; - if (invalid_nodeid(outarg.nodeid)) + if (invalid_nodeid(outarg.nodeid) || fuse_invalid_attr(&outarg.attr)) goto out_put_forget_req; if ((outarg.attr.mode ^ mode) & S_IFMT) @@ -918,7 +926,8 @@ static int fuse_do_getattr(struct inode args.out.args[0].value = &outarg; err = fuse_simple_request(fc, &args); if (!err) { - if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { + if (fuse_invalid_attr(&outarg.attr) || + (inode->i_mode ^ outarg.attr.mode) & S_IFMT) { make_bad_inode(inode); err = -EIO; } else { @@ -1230,7 +1239,7 @@ static int fuse_direntplus_link(struct f if (invalid_nodeid(o->nodeid)) return -EIO; - if (!fuse_valid_type(o->attr.mode)) + if (fuse_invalid_attr(&o->attr)) return -EIO; fc = get_fuse_conn(dir); @@ -1707,7 +1716,8 @@ int fuse_do_setattr(struct dentry *dentr goto error; } - if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { + if (fuse_invalid_attr(&outarg.attr) || + (inode->i_mode ^ outarg.attr.mode) & S_IFMT) { make_bad_inode(inode); err = -EIO; goto error; --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -909,6 +909,8 @@ void fuse_ctl_remove_conn(struct fuse_co */ int fuse_valid_type(int m); +bool fuse_invalid_attr(struct fuse_attr *attr); + /** * Is current process allowed to perform filesystem operation? */