Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp895830yba; Thu, 18 Apr 2019 11:22:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1HjjqQi2anCxROoFoSX2P9eQoc8/dgEhThHDLQoLBg7hvpV61xIqJX76KmJLla8nVTd6a X-Received: by 2002:a63:ef4c:: with SMTP id c12mr77458246pgk.43.1555611757345; Thu, 18 Apr 2019 11:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555611757; cv=none; d=google.com; s=arc-20160816; b=sE9J3gTfZrMQ2zQNJZH33pRuWZk2lvzcIORGF+cShok2QBdGzdaC0/x1Ewwnt4cD0T x1ld391LF0Hozi1M2d2ITIj/FJpLWaLTGITjggPrmz+ww33ZreasZ6QVT7gkvWg4JCQn 9bhIUuySfihvpIENZdoSYcryefzHLN8+RL7E68gnBDoXDoSLA6p7c4xFcFET4WO5Kdyy TstjP7KGjjJpXbt1AkUtXjlK43YA10jZ7y+8mFyEXal4gJM/d7rXg3VC0lQv4IDqf8Fm ISi7wHhYrpSZ2vJG9Y93Rk0VkJoc0ttMt5aYz95vbrFCr2vMd7k772nPkE3w9vIvHdDT r/lw== 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=jaYBPOVb4kuT6AOHOGVW59d7qSMp4ZWdaPwp3+ctDH8=; b=jikxW5viht2dSPrhVfVX4dnC2MY19DiZyu0LUAKOG0j+H3MqYyxCXYO0Mftx3syH90 z1Jf2tJBXW1ixNU3WjbUtVOqCXkhaA3n8gz1d3W2ZfsdtMyzs6z3G38eBQlzx9Sb2iOc zXnn42kEAENRn07lKpd+Neoywm1R5JyyaLJd5qMtXNbEj5Vsr2tCe9qMgt135mVapFCD XxdQf1vD1LCmCeUH3Tn68HlRT/KsS51rNGowVUgxAYgkCksonf/TuhvSSpKW1Er/1ITF 4Zzt3xu+enTkcJaLnKdOpuy7DrZXM+lJna8dDD4sR86k4FZb301KAeGTsdmzS5EGCqTf Q+Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HDxanGvp; 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 a8si2725230pla.362.2019.04.18.11.22.22; Thu, 18 Apr 2019 11:22:37 -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=HDxanGvp; 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 S2403915AbfDRSJ2 (ORCPT + 99 others); Thu, 18 Apr 2019 14:09:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:40968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403812AbfDRSJW (ORCPT ); Thu, 18 Apr 2019 14:09:22 -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 2B78421871; Thu, 18 Apr 2019 18:09:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555610961; bh=RZA4zKN0DEgTHGJnZuFocAeEiEyRGVTzKeDohS9PQHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HDxanGvpe36f+YPZTltAwBFnkNEauYnIj1iNoqeixMLfYi3gY9/pL8Kp05mlGDSPE BfKlvkAFSe63jT+fhxvQEOg2mmdf5RZhiAHxfwRUyXz5MEvrLNw0fnSONGSOG37XJu NAbMc5ViUrIsbmqR86XIArTyBcK3uYpiDWdI/RAY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gertjan Halkes , Dominique Martinet , Sasha Levin Subject: [PATCH 4.9 30/50] 9p: do not trust pdu content for stat item size Date: Thu, 18 Apr 2019 19:57:41 +0200 Message-Id: <20190418160426.455222420@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160422.455656724@linuxfoundation.org> References: <20190418160422.455656724@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 [ 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 145f80518064..7f1b45c082c9 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -570,9 +570,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