[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-4.18 v1] xen/common: Don't dereference overlay_node after checking that it is NULL


  • To: Julien Grall <julien@xxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Wed, 10 Jan 2024 12:25:57 -0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Inpf2mpS27KMeYkyYmNBEi7e3NL3gM3HocX5uPz7iqw=; b=KruJ/IE2xjpSMBCkcBJJa5LIsvXy1ukJALbiIR48Rtjbp0P/ggUuD9q3Pv1Pr7G3aPt68VZj8h3vSLELMNIvLUkHSeTE9ZGs5RWAtUpLPrXwGP4ClIMzsjruLa3SeuWtvtV8Ie6iN7+nr3bNTRS0ve8XirC77B93LWwuqSsFtLCX3Dzccq6eC7YRdV7DcjqeIQ+tSylnTbUcopO8zSHxQuo8kt4Z6Btjlu+LMlGzOajAHGTe5UXabn1PHM/JnKPeeYeQLkqKjU4tm7XL6JFGf+0smc2FLhLkOuRVmzWDXI9d4MrN2Fc5pSpPttYlCZAeVVNquq+NPmaZ+za7hQZl7w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WkQghcuCVaxuvzvoVs5yRlzeIqYizxx2scm1Vs3D8wGluQ+jaNP6A6mB3QHwJaqgvkaovCeSwMUNSsqWYHkBzKs6UHROx/jy6vVBAlXDBx46WPcz5T7+AiTGQA4+zdXT/u7nPW9nODi4Bex4QdmEv68LcXMAiU9A/CA3UNTHyooaf1gB3IV+LJ0ttt7ajRS1wn7tIEOC9jHkxgntRcxj1re2boO6k02l6EsQV+lr5B3sA70273E2cXmTCYYgv6YnaPntz9XydPz2eHq346vlTn6qeIR7K6+a/cXAj5sQK+cD7lN+d5GPekZv8mgeAnUA9mLJbirp/5VA7uKP+i1m2g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: Javi Merino <javi.merino@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Wed, 10 Jan 2024 20:26:17 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Javi,
Thank you for spotting and fixing this.
On Tue, Jan 09, 2024 at 03:31:55PM +0000, Julien Grall wrote:
> Hi Javi,
> 
> Title: Any reason this is titled for-4.18? Shouldn't this patch also be
> merged in staging?
> 
> On 09/01/2024 14:19, Javi Merino wrote:
> > In remove_nodes(), overlay_node is dereferenced when printing the
> > error message even though it is known to be NULLL.  Fix the error
> 
> Typo: s/NULLL/NULL/
> 
> This can be fixed on commit if there is nothing else.
> 
> > message to avoid dereferencing a NULL pointer.
> > 
> > The semantic patch that spots this code is available in
> > 
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/null/deref_null.cocci?id=1f874787ed9a2d78ed59cb21d0d90ac0178eceb0
> 
> Good catch and glad to see that coccinelle can work on Xen. I am looking
> forward for more work in that area :).
> 
> > 
> > Fixes: 7e5c4a8b86f1 ("xen/arm: Implement device tree node removal 
> > functionalities")
> > Signed-off-by: Javi Merino <javi.merino@xxxxxxxxx>
> c> ---
> > CC: Vikram Garhwal <vikram.garhwal@xxxxxxx>
> > 
> > Vikram, I didn't know what to put in the error message.  Feel free to
> > suggest something more appropriate than "Device not present in the
> > tree".
> 
> More questions for Vikram, looking at the code, it is not 100% clear in
> which condition overlay_node could be NULL. Is this a programming error? if
> so, maybe this should be an ASSERT_UNREACHABLE() (could be added separately)
> and it would be fine to print nothing.
> 
This can happen with failures in add_nodes() function. add_nodes() failure will
try to call remove_nodes function. Depending on where add_nodes() is failed,
nodes_address may or may not be NULL.

We also added a detailed comment on this:
https://github.com/xen-project/xen/blob/5a3ace21f3d779b291a2d305824b2820d88de7f1/xen/common/dt-overlay.c#L816

For now, we can return from here without printing anything as error message will
be printed by the caller of remove_nodes() anyway.

> Cheers,
> 
> -- 
> Julien Grall



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.