Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2299816ybl; Thu, 19 Dec 2019 11:12:54 -0800 (PST) X-Google-Smtp-Source: APXvYqygqavKrRh8bnbYz03EoASybzYf4Fh8Vnss72DCg9v7dO2OF+yg2/KCT6xxaMWcdZZxoNQl X-Received: by 2002:aca:61c4:: with SMTP id v187mr3051095oib.8.1576782774701; Thu, 19 Dec 2019 11:12:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782774; cv=none; d=google.com; s=arc-20160816; b=hcckpJDRLRNF9p3f4CudD+grJ9X7hL49KWw2qu3IhqlSYs1ljnhVEuQKRmX75kXDhl vXpBWHauCY3JZT8oFHR/DffOuKv2RnnZVbH/ppiSsD27A4eeBsIiLTLwLqw1boovzh4m 6kHo+POQuFzczx9WgZNxDGBnusbEhghis8imQXdg+LcAQOilureL2cxbZ6tuv1pBh9i6 zs+8Brt/LBR6rPSB0U2L9/kC87ZqjERUZ+IXmHnEduyvgngBogOK1zU3Usd+LOSn4gWQ jE0yeb241inX5jhxKDypYqRmas5F2sT++8pLNXPStFvf//OKiPalvkRG0ChFamOPB6v2 9m8Q== 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=TgZwnTEGj3nY/aijvE7A1CrONlhvTwhS21v8sTsC0YY=; b=pNrPs8HsrJaNueXhSt5ltFwIP9zsa8jWPz6vli27U3+U4xX7QivhTqcNoMObas4Rx5 T8f6IIYjjXC2Igo7hPtNHz6LOiEA5xeXES+pECvOj7ihrQpXrSUiQIfttX+ELisre0eW pteaaorBFVBynjElLhCjGphNEEDcCwSwEYawBWMb2kGgRR7RO23Pj8Reg1OueTP5Mt0D CJd+74Tx4DtkTMU42k+13UJc5+W6XdlhsK1ufbaQCpNz6PuR886L9PBnq6bjNCkYCG+1 xeYH1rvYuHQSBLBS1zBKWyb3nWJ6NkIER7WpsPeguK0QqJvImfsZcaE1QvIU6LtoBGhr ZBSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yh3eFwiT; 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 k7si2323133oib.115.2019.12.19.11.12.43; Thu, 19 Dec 2019 11:12:54 -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=yh3eFwiT; 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 S1727809AbfLSShW (ORCPT + 99 others); Thu, 19 Dec 2019 13:37:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:54778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727767AbfLSShS (ORCPT ); Thu, 19 Dec 2019 13:37:18 -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 CF2CA24679; Thu, 19 Dec 2019 18:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780637; bh=/2y428DZ9/7flek+FERqmdl3zOPt5kbdF28aKkoGOJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yh3eFwiT0vLmDlIgbrlYRKGInqfv04GTR79LME5piXYz1rh9OHuhZ7b8z8cuWjH5B kxHFBX7y0Yso9bdXAFqPiHT/+OqIWtj0RH5CMb6rqfJTPrjg8pnNczocXqao95H3MB k/azOaqxzwaNqzJSvJB0vD/ZHKFeXT21L05yE1YE= 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.4 055/162] fuse: verify attributes Date: Thu, 19 Dec 2019 19:32:43 +0100 Message-Id: <20191219183211.237804822@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@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 @@ -240,7 +240,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; fuse_change_attributes(inode, &outarg.attr, @@ -282,6 +283,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, struct qstr *name, struct fuse_entry_out *outarg, struct inode **inode) { @@ -313,7 +320,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, @@ -433,7 +440,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; @@ -539,7 +547,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) @@ -893,7 +901,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 { @@ -1198,7 +1207,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); @@ -1670,7 +1679,8 @@ int fuse_do_setattr(struct inode *inode, 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 @@ -887,6 +887,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? */