public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Christian A. Ehrhardt" <lk@c--e.de>
To: coverity-bot <keescook@chromium.org>
Cc: Jameson Thies <jthies@google.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Fabrice Gasnier <fabrice.gasnier@foss.st.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	linux-usb@vger.kernel.org, Benson Leung <bleung@chromium.org>,
	Saranya Gopal <saranya.gopal@intel.com>,
	Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
	Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
	Prashant Malani <pmalani@chromium.org>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	linux-next@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: Coverity: ucsi_check_cable(): Null pointer dereferences
Date: Thu, 7 Mar 2024 21:16:00 +0100	[thread overview]
Message-ID: <ZeoggIXSLy+lVHP1@cae.in-ulm.de> (raw)
In-Reply-To: <202403071134.7C7C077655@keescook>


Hi,

On Thu, Mar 07, 2024 at 11:34:21AM -0800, coverity-bot wrote:
> Hello!
> 
> This is an experimental semi-automated report about issues detected by
> Coverity from a scan of next-20240307 as part of the linux-next scan project:
> https://scan.coverity.com/projects/linux-next-weekly-scan
> 
> You're getting this email because you were associated with the identified
> lines of code (noted below) that were touched by commits:
> 
>   Tue Mar 5 13:11:08 2024 +0000
>     f896d5e8726c ("usb: typec: ucsi: Register SOP/SOP' Discover Identity Responses")
> 
> Coverity reported the following:
> 
> *** CID 1584245:  Null pointer dereferences  (FORWARD_NULL)
> drivers/usb/typec/ucsi/ucsi.c:1136 in ucsi_check_cable()
> 1130     	}
> 1131
> 1132     	ret = ucsi_register_cable(con);
> 1133     	if (ret < 0)
> 1134     		return ret;
> 1135
> vvv     CID 1584245:  Null pointer dereferences  (FORWARD_NULL)
> vvv     Passing "con" to "ucsi_get_cable_identity", which dereferences null "con->cable".
> 1136     	ret = ucsi_get_cable_identity(con);
> 1137     	if (ret < 0)
> 1138     		return ret;
> 1139
> 1140     	ret = ucsi_register_plug(con);
> 1141     	if (ret < 0)
> 
> If this is a false positive, please let us know so we can mark it as
> such, or teach the Coverity rules to be smarter. If not, please make
> sure fixes get into linux-next. :) For patches fixing this, please
> include these lines (but double-check the "Fixes" first):

This looks like a false positive to me. The code looks like this:

	if (con->cable)
		return 0;
	[ ... ]
	ret = ucsi_register_cable(con)
	if (ret < 0)
		return ret;
	ret = ucsi_get_cable_identity(con);
	[ ... ]

From the con->cable check coverity concludes that con->cable is
initially NULL. Later ucsi_register_cable() initializes con->cable
if successful. Coverity seems to miss this and still thinks that
con->cable is NULL. Then converity correctly notices that
ucsi_get_cable_identity() dereferences con->cable and complains.

     regards  Christian


  reply	other threads:[~2024-03-07 20:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 19:34 Coverity: ucsi_check_cable(): Null pointer dereferences coverity-bot
2024-03-07 20:16 ` Christian A. Ehrhardt [this message]
2024-03-07 20:22   ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZeoggIXSLy+lVHP1@cae.in-ulm.de \
    --to=lk@c--e.de \
    --cc=abhishekpandit@chromium.org \
    --cc=bleung@chromium.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavo@embeddedor.com \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=jthies@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=pmalani@chromium.org \
    --cc=saranya.gopal@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox