Subject: Re: [PATCH net] rtnetlink: Return correct error on changing device netns

From: Stephen Hemminger <[email-masked]>
Date: Mon, 30 Aug 2021 07:59:48 -0700

On Thu, 26 Aug 2021 11:15:22 -0500
[email-masked] (Eric W. Biederman) wrote:

> The analysis and the fix looks good to me.
> 
> The code calling do_setlink is inconsistent.  One caller of do_setlink
> passes a NULL to indicate not name has been specified.  Other callers
> pass a string of zero bytes to indicate no name has been specified.
> 
> I wonder if we might want to fix the callers to uniformly pass NULL,
> instead of a string of length zero.
> 
> There is a slight chance this will trigger a regression somewhere
> because we are changing the error code but this change looks easy enough
> to revert in the unlikely event this breaks existing userspace.
> 
> Reviewed-by: "Eric W. Biederman" <[email-masked]>

This patch causes a new warning from Coverity:
________________________________________________________________________________________________________
*** CID 1490867:  Null pointer dereferences  (FORWARD_NULL)
/net/core/rtnetlink.c: 2701 in do_setlink()
2695     
2696     	/*
2697     	 * Interface selected by interface index but interface
2698     	 * name provided implies that a name change has been
2699     	 * requested.
2700     	 */
>>>     CID 1490867:  Null pointer dereferences  (FORWARD_NULL)
>>>     Dereferencing null pointer "ifname".  
2701     	if (ifm->ifi_index > 0 && ifname[0]) {
2702     		err = dev_change_name(dev, ifname);
2703     		if (err < 0)
2704     			goto errout;
2705     		status |= DO_SETLINK_MODIFIED;
2706     

Originally, the code was not accepting ifname == NULL and would
crash. Somewhere along the way some new callers seem to have gotten
confused.

What code is call do_setlink() with NULL as ifname, that should be fixed.