Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3958442pxv; Mon, 26 Jul 2021 16:56:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysPzNZsQyjvt9kC2ptY2kgTBOnkBAZrf/a8rRhABm1cdZhwb9XeJOzPMF1Y3aqaE5M2eTY X-Received: by 2002:a17:906:3b0b:: with SMTP id g11mr19720811ejf.286.1627343774413; Mon, 26 Jul 2021 16:56:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627343774; cv=none; d=google.com; s=arc-20160816; b=UUEm/G0YgsGWluk5G4J1ybCh0XWRjx7qIZQ0ye/BFvgWKPcz5viYX6MbswZAmpgNwA oXsZZkJOjN5dmsC7TgU3TXqfWGI1MfyWR4aK/uspHZZyhm5lh27nfsrq5LT5LnfVsnIT LnA8lMqSbKhJ0QZIUOSRFbdvIjHLrkfCWu7Ds0cVRb+7EA2YvcFfck19T9Pls7jWn2tm 0mNp+d/InQFDHSMNd6luduxcUByzOT58Ct/ipaGhRb3XG39iGSP6UCnLGSGsmJXXU0xo 1w/DSvRg54fuEj5WeV6rLpRVv3+SpUd+013j5UYaQhnmC+A7UIltYXJz3Khx6EEfOHMv kfTg== 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=Cxc0r7eep6SxYlrrpuwhKUygXsgM7s8ZnU4gh0H8Qpc=; b=EBXemajA87eisZeAJIXsKItDxdmMEe1qTRaOsizrwJoazdN2Gb3p8KFx0XrkmNoGQN tNLl1oQ9ftVMZQya0qVHeFnXPHEsYWDbIiKk2nY2PtXbHHbQT4ZrD9XaB6bxKk10EYrD nQYxKwS7euqO7GEfoFgj9tNiXDXfogJeDKgqgctF7YX+noaFD4267+MAIiBcgfOXJAmd UIiol9AxC9IE9TZBQZExCL74SfG5MPLIRcY2QLn6CRe3LGDWRq3egO1DNRWYw5Q3EnUL jBJVX4ECwUzSi5FcxqiI9Pg13sh+Sll7wVCnUv9lSXsUocwDqdt0A8V+1EjGr9ELw6Bq hu4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XrdBfjd+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si1357290edt.275.2021.07.26.16.55.52; Mon, 26 Jul 2021 16:56:14 -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=k20201202 header.b=XrdBfjd+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234193AbhGZXOD (ORCPT + 99 others); Mon, 26 Jul 2021 19:14:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:48386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233809AbhGZXOC (ORCPT ); Mon, 26 Jul 2021 19:14:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5F31A60F94; Mon, 26 Jul 2021 23:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627343670; bh=iv+ATOSmwiwNnLSQnmZrL8/5KkfaAq/A3X/tsBD9WHo=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=XrdBfjd+bjwD4/0PhyJb6mCaEEXRj94JnYjShRENPJ+i3K7BviN0W/BdTMoM7fMZE vv4ow0zW74MUmAF6RfCSJuC/ROSQtXN28ThJopcNl44LakLmlmBz0LVG3ZjTXYYCuI aLxNGi2KA6R3MNmd+7oWSb4TFMXH+FiWyhNJRUcqDJuYuaSTrcfv4uSeXid0qy0Bzt l9IgKTo3L4J9ua3xKCToQ/k9zBRz6wPhAZ+3YMu2ijRWtEu95gMMRw8CVfjp+7+mS2 15nZ7NODNRZKIUV8nSZzCscTdaltslCtORrxOJHXdRBabS5ZKKqklTtggUi437eDNV NXNcK1ampO7Cw== Date: Mon, 26 Jul 2021 16:54:29 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Harshvardhan Jha cc: Stefano Stabellini , asmadeus@codewreck.org, ericvh@gmail.com, lucho@ionkov.net, davem@davemloft.net, kuba@kernel.org, v9fs-developer@lists.sourceforge.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [External] : Re: [PATCH] 9p/xen: Fix end of loop tests for list_for_each_entry In-Reply-To: Message-ID: References: <20210725175103.56731-1-harshvardhan.jha@oracle.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 27 Jul 2021, Harshvardhan Jha wrote: > On 27/07/21 3:00 am, Stefano Stabellini wrote: > > On Mon, 26 Jul 2021, asmadeus@codewreck.org wrote: > > > Harshvardhan Jha wrote on Sun, Jul 25, 2021 at 11:21:03PM +0530: > > > > The list_for_each_entry() iterator, "priv" in this code, can never be > > > > NULL so the warning would never be printed. > > > > > > hm? priv won't be NULL but priv->client won't be client, so it will > > > return -EINVAL alright in practice? > > > > > > This does fix an invalid read after the list head, so there's a real > > > bug, but the commit message needs fixing. > > > > Agreed > > > > > > > > Signed-off-by: Harshvardhan Jha > > > > --- > > > > From static analysis. Not tested. > > > > > > +Stefano in To - I also can't test xen right now :/ > > > This looks functional to me but if you have a bit of time to spare just > > > a mount test can't hurt. > > > > Yes, I did test it successfully. Aside from the commit messaged to be > > reworded: > How's this? > ===========================BEGIN======================================== > 9p/xen: Fix end of loop tests for list_for_each_entry > > This patch addresses the following problems: > - priv can never be NULL, so this part of the check is useless > - if the loop ran through the whole list, priv->client is invalid and > it is more appropriate and sufficient to check for the end of > list_for_each_entry loop condition. > > Signed-off-by: Harshvardhan Jha That's fine > --- > From static analysis. Not tested. > ===========================END========================================== > > > > Reviewed-by: Stefano Stabellini > > Tested-by: Stefano Stabellini > > > > > > > > --- > > > > net/9p/trans_xen.c | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c > > > > index f4fea28e05da..3ec1a51a6944 100644 > > > > --- a/net/9p/trans_xen.c > > > > +++ b/net/9p/trans_xen.c > > > > @@ -138,7 +138,7 @@ static bool p9_xen_write_todo(struct > > > > xen_9pfs_dataring *ring, RING_IDX size) > > > > static int p9_xen_request(struct p9_client *client, struct p9_req_t > > > > *p9_req) > > > > { > > > > - struct xen_9pfs_front_priv *priv = NULL; > > > > + struct xen_9pfs_front_priv *priv; > > > > RING_IDX cons, prod, masked_cons, masked_prod; > > > > unsigned long flags; > > > > u32 size = p9_req->tc.size; > > > > @@ -151,7 +151,7 @@ static int p9_xen_request(struct p9_client *client, > > > > struct p9_req_t *p9_req) > > > > break; > > > > } > > > > read_unlock(&xen_9pfs_lock); > > > > - if (!priv || priv->client != client) > > > > + if (list_entry_is_head(priv, &xen_9pfs_devs, list)) > > > > return -EINVAL; > > > > num = p9_req->tc.tag % priv->num_rings; >