Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp769760ybl; Wed, 11 Dec 2019 07:15:39 -0800 (PST) X-Google-Smtp-Source: APXvYqwCs7FzPQtyCXCKMXRFFGACu6rItcgFfh9F2JIUoDireIDZflS6rE8iB8gD/EaOYDWn7rLa X-Received: by 2002:a9d:53c2:: with SMTP id i2mr2462257oth.43.1576077339306; Wed, 11 Dec 2019 07:15:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077339; cv=none; d=google.com; s=arc-20160816; b=yFxkTyR0l3GPYZtRk26klo8P1ynp8jcSZIFS2xhjTV78ONfnXHI5dG4flxBbcYYOCn x952hols8wElqqrYv7+5O/lhZ08PuRp+cOlDouwYeOtxwJHkPA6h4+RrY6FfX7DR+TAS hlOHxlL/gAZcV85gbYgzkIBwGG3A4G//PYkx0uMv+XAI8I9nfWdVUbZlXT5sYdhUR7B0 ZK11CuW/YzcIQ3SW8IkvLmiuVgbefHI272ohnFC5ycxrwvLthI3pB+/6b/fWrW9/xHnp PVrRG3tHPnnC9A0eEb6AqQZbdOtvKq/eTNMjFR1DFFerKpNLVJ28z+MU8KGSkBpqyDaS 5kUg== 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=jcuVT+BlnZvrYzKrngT1yce67mk+s2lTqv4Su29WsrQ=; b=YNPztylTBD/bbbcxYQg1FZWIwbhwMXXlbLLotnOM3Fhtr8+HPkP+6gdSrICKOhpOfy KXh6H3/kSGIjq4Ibld74W7m36bxH+XZznJG1qoRrOL++5uSu2BtY1EIENZZLWthtIrv2 UWQ9tL2Om1VAdJQHMdvkeTv5xMeOM4DvyyTr4i7eSv/P4nmpqLOWdZZ/cz6m68b99vXp FDrcA2LB30zUQ7F3F3s79BC9CCN/gC7mrcE9S4cMmG5WuF6dDsRE0/yVqp58zPQC62NQ Se7cUiv1fWbnmoL05Xt3nNs04s3KS+WYARj+MCfZn68FSN01qyfkgqpLyTskghqdDHyu WZXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h89My+4L; 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 w26si1167252otl.213.2019.12.11.07.15.27; Wed, 11 Dec 2019 07:15: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=h89My+4L; 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 S1731643AbfLKPOg (ORCPT + 99 others); Wed, 11 Dec 2019 10:14:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:37712 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730448AbfLKPNo (ORCPT ); Wed, 11 Dec 2019 10:13:44 -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 C3FF32465C; Wed, 11 Dec 2019 15:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077223; bh=34+cUa3MGnMCqTQUnF3QD+tWh95FD6XBhUFLhlsOcnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h89My+4L9ZLVxs/M7LD77g2LZfPn0dfqlN1+L/XovrI1q68sjF271fH9Z+wSgl6Pp 31H3py0Va+XPcDCG8Ak/e9UsjGV9WlcSGkjR1GoPS2ylWVk7KtZDJLzYHTmvpLE46M BIL3EO8bDZlpH4ZWM2n3caz8YXzjAHCqR9r19XJc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arijit Banerjee , Miklos Szeredi Subject: [PATCH 5.3 046/105] fuse: verify attributes Date: Wed, 11 Dec 2019 16:05:35 +0100 Message-Id: <20191211150240.151473315@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@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 | 22 ++++++++++++++++------ fs/fuse/fuse_i.h | 2 ++ fs/fuse/readdir.c | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -214,7 +214,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); @@ -272,6 +273,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) { @@ -303,7 +310,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, @@ -427,7 +434,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; @@ -535,7 +543,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) @@ -895,7 +903,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 { @@ -1518,7 +1527,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 @@ -1008,6 +1008,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? */ --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -184,7 +184,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);