Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2079140ybb; Fri, 29 Mar 2019 18:30:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVSu2A+riXjWIZgzmJAdoL3XS7kekwBXcOajVSjg/PW57+/faQadRisZrO+/zv3kf+g8z6 X-Received: by 2002:a63:4a5a:: with SMTP id j26mr39587957pgl.361.1553909401625; Fri, 29 Mar 2019 18:30:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553909401; cv=none; d=google.com; s=arc-20160816; b=IJt3p5t7VjaK5LG8cdfEIAhwnNkwszg3KxZ5SUF6ijIqLuOm7gFMIhGe2A2xMLrXXm oGdhWniNooEC4ejYnLmTgK2Sw549kj4oL1stddn+vrv435/4uGIGUf9XApct4j4ir1X6 AGLGpDb24HUmWx0vbLAaxuwtv+z0Rb07v6Vi73IHnX/s5qat6jTiwWnGyz07YTGo68oH YzP4kLrOyaYgjjxespCwjy26yVZ6YNJiWde5enhVcak+4m4kku/RRfwWdosc2klDDgKi gG/Icdg5SCbhjOMJP8pctuXjHneaEPr6DIAzAh9TvSkg2G2I7dXx9shaKiAgFGsMespK R6xA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6RuaD/vvzUSbN/ePwEdv/2DZSYkfGnvmSEYRvHxdNWA=; b=ncBgfXCvD6PpRtT1EbCQBH6xGQRf/3+NN4EFxAEZU61sG98lHYQOHSXgTl0XLY2dgA C5PaxDN8+M4x4qHeDuFkD5ZcxXxwAVAxLW497yhh+oKpQ2KhLWJiIXxXRIYK2d+BtMOq rObce/Cnx12pUeXXtNhp9ygayEkO7NQmJD5fEyvhZUDap6K47+wQg4o/OLCeAzMHyy01 sTkx7eOt9zmpVTu1GVUpe5WefQ4CGA6HzBV0w1rBSwco0DwLzMC5H7qIVJy1a0R9wm3B Ko2uwM+1WGDFdfMJz95yr7P88AoFK+bkcgsYW22nIhMB2P3D4O7/PtrM4ywOeZ6GebzJ QLQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mgtsXfNB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 59si3329489plb.405.2019.03.29.18.29.46; Fri, 29 Mar 2019 18:30:01 -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=mgtsXfNB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730741AbfC3B3D (ORCPT + 99 others); Fri, 29 Mar 2019 21:29:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:35766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730696AbfC3B3B (ORCPT ); Fri, 29 Mar 2019 21:29:01 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 047772184C; Sat, 30 Mar 2019 01:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909340; bh=0I/1J8aJfN5I88jHgPiNoG0KtScanBcpje0vOD93KKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mgtsXfNB5n3gQF0R8+rJ2hAMg5cXMWjoll2fs0UyucK7CJrvfnFBalz0BsJ9Q3XXe Iw4JAXN9j4tK6+A0fnPxO2U92gHqoMKisw3j76mhKsu6YoSN0BvJx4y4VWp4Sfc2CZ cyFpmzswYqi7qT2YztnbraHZA5Vx2hhN9zhEEvec= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Gertjan Halkes , Dominique Martinet , Sasha Levin , v9fs-developer@lists.sourceforge.net, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 05/57] 9p: do not trust pdu content for stat item size Date: Fri, 29 Mar 2019 21:27:58 -0400 Message-Id: <20190330012854.32212-5-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330012854.32212-1-sashal@kernel.org> References: <20190330012854.32212-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gertjan Halkes [ Upstream commit 2803cf4379ed252894f046cb8812a48db35294e3 ] v9fs_dir_readdir() could deadloop if a struct was sent with a size set to -2 Link: http://lkml.kernel.org/r/1536134432-11997-1-git-send-email-asmadeus@codewreck.org Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=88021 Signed-off-by: Gertjan Halkes Signed-off-by: Dominique Martinet Signed-off-by: Sasha Levin --- fs/9p/vfs_dir.c | 8 +++----- net/9p/protocol.c | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 48db9a9f13f9..cb6c4031af55 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -105,7 +105,6 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) int err = 0; struct p9_fid *fid; int buflen; - int reclen = 0; struct p9_rdir *rdir; struct kvec kvec; @@ -138,11 +137,10 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) while (rdir->head < rdir->tail) { err = p9stat_read(fid->clnt, rdir->buf + rdir->head, rdir->tail - rdir->head, &st); - if (err) { + if (err <= 0) { p9_debug(P9_DEBUG_VFS, "returned %d\n", err); return -EIO; } - reclen = st.size+2; over = !dir_emit(ctx, st.name, strlen(st.name), v9fs_qid2ino(&st.qid), dt_type(&st)); @@ -150,8 +148,8 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) if (over) return 0; - rdir->head += reclen; - ctx->pos += reclen; + rdir->head += err; + ctx->pos += err; } } } diff --git a/net/9p/protocol.c b/net/9p/protocol.c index ee32bbf12675..b4d80c533f89 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -571,9 +571,10 @@ int p9stat_read(struct p9_client *clnt, char *buf, int len, struct p9_wstat *st) if (ret) { p9_debug(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret); trace_9p_protocol_dump(clnt, &fake_pdu); + return ret; } - return ret; + return fake_pdu.offset; } EXPORT_SYMBOL(p9stat_read); -- 2.19.1