From: Greg KH <gregkh@linuxfoundation.org>
To: RD Babiera <rdbabiera@google.com>
Cc: heikki.krogerus@linux.intel.com, badhri@google.com,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v1] usb: typec: altmodes/displayport: add null pointer check for sysfs nodes
Date: Tue, 30 Jan 2024 15:08:45 -0800 [thread overview]
Message-ID: <2024013021-fetal-nifty-38d4@gregkh> (raw)
In-Reply-To: <20240130192638.3557409-2-rdbabiera@google.com>
On Tue, Jan 30, 2024 at 07:26:39PM +0000, RD Babiera wrote:
> The DisplayPort driver's sysfs nodes may be present to the userspace before
> typec_altmode_set_drvdata() completes in dp_altmode_probe. This means that
> a sysfs read can trigger a NULL pointer error by deferencing dp->hpd in
> hpd_show or dp->lock in pin_assignment_show, as dev_get_drvdata() returns
> NULL in those cases.
>
> Verify dp drvdata is present in sysfs reads and writes before proceeding.
Why not populate the sysfs nodes after the assigment happens? That's
the normal way to do this, otherwise your change looks odd because:
>
> Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: RD Babiera <rdbabiera@google.com>
> ---
> drivers/usb/typec/altmodes/displayport.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index 5a80776c7255..0423326219d8 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -518,6 +518,9 @@ configuration_store(struct device *dev, struct device_attribute *attr,
> int con;
> int ret = 0;
>
> + if (!dp)
> + return -ENODEV;
> +
> con = sysfs_match_string(configurations, buf);
there's nothing keeping dp from being an invalid pointer right after you
check it. Really that might not happen, but it's hard to tell that
here.
thanks,
greg k-h
next prev parent reply other threads:[~2024-01-30 23:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 19:26 [PATCH v1] usb: typec: altmodes/displayport: add null pointer check for sysfs nodes RD Babiera
2024-01-30 23:08 ` Greg KH [this message]
2024-02-26 22:54 ` RD Babiera
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=2024013021-fetal-nifty-38d4@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=badhri@google.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rdbabiera@google.com \
--cc=stable@vger.kernel.org \
/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