Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4419895pxa; Mon, 10 Aug 2020 08:39:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBWqaCpydzHEX/1/o5OvaTjyK1GnBu5vfGdwcloKmGUpBKNdMYpZHCjcScjYk0vpT1YAlD X-Received: by 2002:a17:907:11c3:: with SMTP id va3mr23014515ejb.497.1597073991055; Mon, 10 Aug 2020 08:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073991; cv=none; d=google.com; s=arc-20160816; b=bHUEU8hR3Rl7f2d0yBr8kaDiLIYTFCnQ+gwQQWvScCcfLS2GYW3bX5uxrw1Dwj5y3p lYnsYavWNRtc2WCq5it3bMXBrX8skbgEq+JJRyGI56c/GDsR7djNtYZsm9xcb+A4BVF8 wygaXvSCgFB3V/8PSx07d0eEsC0+FgPPdwP/JCjdnGyfamp2B8YezLgCp9c3GMUUxbe0 ZIAb1jzNCs8eg/rrTeDNe+ICVweQmgr9+lrCnkd/LHbRfFy03gyuAaaiSPg2OcSmi/DA YPxGT0q6G/BwL5mDBwhTcYbeGSxd+OqdeaEu9HrJ2mAo3GXD7YFZ+56ZrnsLMX8rO0Cr J0aA== 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=nd8JpA3gmjXHSVNriaTr3MXRieu6qj/Ia8M/NegbmCk=; b=P4gcHsTf97efxKto3p8AhEOhCDzriGPm2zrd62kJu9ICoWQGiZdjx5cUZKAuoUj6F2 43fkc1enF1fGUn+VNNpq8n75u9/SBc2ZnzYC2yCHkZEuEJzlFtkXbBjSyJ4ZRpDZlw1O dic0/pSbzSHgJpXRc37E0u0ff4IpmeddYQDVJpbDXo983RcZ/2hiwg0+O6XRiDvLqGGy 6pjHVNPg8+DxviPA4Z/GFasGab5Us2o1h584ThB4KOVbCL25umIHUMXtl1vYaItkjjZQ BQE3MVtIngR/Z06VeEkWjBBM6mYbIHWHs1O6YSdSzQqsgPPALK55ofSO6qU//AxJJrRZ TjbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z7rNJHLY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w21si10344959edi.330.2020.08.10.08.39.27; Mon, 10 Aug 2020 08:39:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z7rNJHLY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727889AbgHJPgs (ORCPT + 99 others); Mon, 10 Aug 2020 11:36:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:32950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728165AbgHJP1H (ORCPT ); Mon, 10 Aug 2020 11:27:07 -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 2F0DD22CF7; Mon, 10 Aug 2020 15:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597073226; bh=1fgeCoTwmpji+1gz0ECi45OvDJ5prtYx5oK3gPIZZ2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z7rNJHLY4v+mR+P205pwVzz3j9w3NCGD7eokn7Fml+nlQJY0xpgHAwCT6kLN0XGPj ift+DPMWtAgTpp5IU88WrbOn6y7EdKqbkrpcJXuFb3DHiZ8oRZDZSyacBp3oR0YA4r WgRJm/XX1DFL2dztz0S8vNY+O3eVmZlkEuvJ5Bmw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+e6f77e16ff68b2434a2c@syzkaller.appspotmail.com, Christoph Hellwig , Dominique Martinet , Sasha Levin Subject: [PATCH 5.4 31/67] net/9p: validate fds in p9_fd_open Date: Mon, 10 Aug 2020 17:21:18 +0200 Message-Id: <20200810151810.966885622@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151809.438685785@linuxfoundation.org> References: <20200810151809.438685785@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: Christoph Hellwig [ Upstream commit a39c46067c845a8a2d7144836e9468b7f072343e ] p9_fd_open just fgets file descriptors passed in from userspace, but doesn't verify that they are valid for read or writing. This gets cought down in the VFS when actually attempting a read or write, but a new warning added in linux-next upsets syzcaller. Fix this by just verifying the fds early on. Link: http://lkml.kernel.org/r/20200710085722.435850-1-hch@lst.de Reported-by: syzbot+e6f77e16ff68b2434a2c@syzkaller.appspotmail.com Signed-off-by: Christoph Hellwig [Dominique: amend goto as per Doug Nazar's review] Signed-off-by: Dominique Martinet Signed-off-by: Sasha Levin --- net/9p/trans_fd.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 3f67803123be2..12ecacf0c55fb 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -816,20 +816,28 @@ static int p9_fd_open(struct p9_client *client, int rfd, int wfd) return -ENOMEM; ts->rd = fget(rfd); + if (!ts->rd) + goto out_free_ts; + if (!(ts->rd->f_mode & FMODE_READ)) + goto out_put_rd; ts->wr = fget(wfd); - if (!ts->rd || !ts->wr) { - if (ts->rd) - fput(ts->rd); - if (ts->wr) - fput(ts->wr); - kfree(ts); - return -EIO; - } + if (!ts->wr) + goto out_put_rd; + if (!(ts->wr->f_mode & FMODE_WRITE)) + goto out_put_wr; client->trans = ts; client->status = Connected; return 0; + +out_put_wr: + fput(ts->wr); +out_put_rd: + fput(ts->rd); +out_free_ts: + kfree(ts); + return -EIO; } static int p9_socket_open(struct p9_client *client, struct socket *csocket) -- 2.25.1