Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5048765rwb; Mon, 21 Nov 2022 16:00:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf59m0HMGmvl1rrbWb59uOHgNbYRNLMnGmmfsoajLDXuMMWw1PQY6Xct5koRnawPT3ThhtZR X-Received: by 2002:a17:903:1206:b0:186:a2ef:7a74 with SMTP id l6-20020a170903120600b00186a2ef7a74mr5059343plh.148.1669075204712; Mon, 21 Nov 2022 16:00:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669075204; cv=none; d=google.com; s=arc-20160816; b=kyGGD17qJ+d9inySFpAiaI/2m1ifGijryEDv5LThwJPzMoZMXwdmWIRna+jqNZHeG0 sHp5jjmTkBnszPJa908lb02drcmj4iXqgOPCG7nq25IdGaBGMxP2kni1NxGR/wKh4qFC ry6D3m7Kgpcyzoq64WaNRegXSVlpb66T94gnaz2GXjP636575wbL16+kLdR6IOkBA53r IlgVCodaPMmb5iSk8OuOaXmMkKzKZaRcjtazfLrcJuESoeByP0AMuxrYHsAykxjEQLxx ZidUA0Ka1LGqaC2MP/JsDVjxbD2z6fOyT8e+tdXW+e8F2oOmeuiMSubND59IGkrtnv+H B++w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=8xmTN0+jHD3TbhyXOVEAKEiECQoFTCIEoVXpBVC+Uag=; b=xOGcORs7gXTtQFh7LkqGgKjqEixuge+t597zcAzFFmS90pmnppoq24tiwkRaiHZ/4d l18e9ifLMgbV8nzyU661zpbcyt/3x4bNSSmMlf4l2WMpUAuK3GgdFqvmKr5JctpCIOQx yvy3i7bY2WSnMyid/Z4yt5K4bYVmAYUJQILs2dCnIX7OJuqALzZKijEw22+TxHG9MEYq Rx66yvQBvfOyjL8FkQktdYUQXWsWNQuORgtlzQpJcozKUpyFx66JP2dLKRX2INadMYFM +7XF/JG2yWylq94DTYa8hz9JBQA6JJCINkk21ETRXfWyZKx86MkaAJNcDzYgU8P1E12q FQXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tMT3E6D8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a7-20020a17090a854700b00212f86579f8si14722729pjw.111.2022.11.21.15.59.52; Mon, 21 Nov 2022 16:00:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tMT3E6D8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229915AbiKUXCD (ORCPT + 92 others); Mon, 21 Nov 2022 18:02:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbiKUXCA (ORCPT ); Mon, 21 Nov 2022 18:02:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49F91CDFFF for ; Mon, 21 Nov 2022 15:01:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F0F6EB816EC for ; Mon, 21 Nov 2022 23:01:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE7EEC433C1; Mon, 21 Nov 2022 23:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669071716; bh=4BiwOETwQYdt5roOa+pyNI4BC0UtBQJIK+gof+CXNgo=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=tMT3E6D8Od7ZaPXYacJ0XmiiEdRQ6J4P13ZPab1S1+rTTaOqC1XLoFw6sxvx8ZK/j ns0TT1bq/e1rr0PqD/S4lSby5OXcQPbhJ+9JxW286Th27f8y3H3Z7e9nOqNsCLP0wO 8/rtl+SbV4mxQ227rClC0S5HldW4+ZTixPjNJqohTtWFxtPD74d3p5WAEFhqLhnHJ6 CWNK1a+SA3O+WWnAD5mDhoncTWhrK3yVnw5/sPAalelDPYE/pmlriv9hqLiD+UdEFn XzlZk+pqQvR5eqPlSPXIYW1D9exxess1/AbZvmmyUDKdabK+WiLbBJEtW6M3IrIscu KRh2t2CbQd/1g== Date: Mon, 21 Nov 2022 15:01:54 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Christian Schoenebeck cc: Stefano Stabellini , Dominique Martinet , GUO Zihua , v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] 9p/xen: check logical size for buffer size In-Reply-To: <37091478.n1eaNAWdo1@silver> Message-ID: References: <20221118135542.63400-1-asmadeus@codewreck.org> <37091478.n1eaNAWdo1@silver> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 21 Nov 2022, Christian Schoenebeck wrote: > On Friday, November 18, 2022 2:55:41 PM CET Dominique Martinet wrote: > > trans_xen did not check the data fits into the buffer before copying > > from the xen ring, but we probably should. > > Add a check that just skips the request and return an error to > > userspace if it did not fit > > > > Signed-off-by: Dominique Martinet > > --- > > > > This comes more or less as a follow up of a fix for trans_fd: > > https://lkml.kernel.org/r/20221117091159.31533-1-guozihua@huawei.com > > Where msize should be replaced by capacity check, except trans_xen > > did not actually use to check the size fits at all. > > > > While we normally trust the hypervisor (they can probably do whatever > > they want with our memory), a bug in the 9p server is always possible so > > sanity checks never hurt, especially now buffers got drastically smaller > > with a recent patch. > > > > My setup for xen is unfortunately long dead so I cannot test this: > > Stefano, you've tested v9fs xen patches in the past, would you mind > > verifying this works as well? > > > > net/9p/trans_xen.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c > > index b15c64128c3e..66ceb3b3ae30 100644 > > --- a/net/9p/trans_xen.c > > +++ b/net/9p/trans_xen.c > > @@ -208,6 +208,14 @@ static void p9_xen_response(struct work_struct *work) > > continue; > > } > > > > + if (h.size > req->rc.capacity) { > > + dev_warn(&priv->dev->dev, > > + "requested packet size too big: %d for tag %d with capacity %zd\n", > > + h.size, h.tag, rreq->rc.capacity); > > + req->status = REQ_STATUS_ERROR; > > + goto recv_error; > > + } > > + > > Looks good (except of s/rreq/req/ mentioned by Stefano already). > > > memcpy(&req->rc, &h, sizeof(h)); > > Is that really OK? > > 1. `h` is of type xen_9pfs_header and declared as packed, whereas `rc` is of > type p9_fcall not declared as packed. > > 2. Probably a bit dangerous to assume the layout of xen_9pfs_header being in > sync with the starting layout of p9_fcall without any compile-time > assertion? You are right. It would be better to replace the memcpy with: req->rc.size = h.size; req->rc.id = h.id; req->rc.tag = h.tag;