* [PATCH] tty: vcc: Add check for kstrdup() in vcc_probe()
@ 2023-09-03 10:13 Yi Yang
2023-09-03 10:49 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Yi Yang @ 2023-09-03 10:13 UTC (permalink / raw)
To: davem, gregkh, jirislaby, jag.raman; +Cc: linux-serial
Add check for the return value of kstrdup() and return the error, if it
fails in order to avoid NULL pointer dereference.
Fixes: 5d171050e28f ("sparc64: vcc: Enable VCC port probe and removal")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
drivers/tty/vcc.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index a39ed981bfd3..420d334f6077 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -579,6 +579,10 @@ static int vcc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
return -ENOMEM;
name = kstrdup(dev_name(&vdev->dev), GFP_KERNEL);
+ if (!name) {
+ kfree(port);
+ return -ENOMEM;
+ }
rv = vio_driver_init(&port->vio, vdev, VDEV_CONSOLE_CON, vcc_versions,
ARRAY_SIZE(vcc_versions), NULL, name);
@@ -624,6 +628,11 @@ static int vcc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
goto unreg_tty;
}
port->domain = kstrdup(domain, GFP_KERNEL);
+ if (!port->domain) {
+ rv = -ENOMEM;
+ goto unreg_tty;
+ }
+
mdesc_release(hp);
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] tty: vcc: Add check for kstrdup() in vcc_probe()
2023-09-03 10:13 [PATCH] tty: vcc: Add check for kstrdup() in vcc_probe() Yi Yang
@ 2023-09-03 10:49 ` Greg KH
2023-09-04 3:45 ` yiyang (D)
0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2023-09-03 10:49 UTC (permalink / raw)
To: Yi Yang; +Cc: davem, jirislaby, jag.raman, linux-serial
On Sun, Sep 03, 2023 at 06:13:22PM +0800, Yi Yang wrote:
> Add check for the return value of kstrdup() and return the error, if it
> fails in order to avoid NULL pointer dereference.
>
> Fixes: 5d171050e28f ("sparc64: vcc: Enable VCC port probe and removal")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
> drivers/tty/vcc.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
> index a39ed981bfd3..420d334f6077 100644
> --- a/drivers/tty/vcc.c
> +++ b/drivers/tty/vcc.c
> @@ -579,6 +579,10 @@ static int vcc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
> return -ENOMEM;
>
> name = kstrdup(dev_name(&vdev->dev), GFP_KERNEL);
> + if (!name) {
> + kfree(port);
> + return -ENOMEM;
Please just add another goto target later in the function like the rest
of the error paths follow.
And how did you test this patch?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] tty: vcc: Add check for kstrdup() in vcc_probe()
2023-09-03 10:49 ` Greg KH
@ 2023-09-04 3:45 ` yiyang (D)
2023-09-04 6:17 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: yiyang (D) @ 2023-09-04 3:45 UTC (permalink / raw)
To: Greg KH; +Cc: davem, jirislaby, jag.raman, linux-serial
On 2023/9/3 18:49, Greg KH wrote:
> On Sun, Sep 03, 2023 at 06:13:22PM +0800, Yi Yang wrote:
>> Add check for the return value of kstrdup() and return the error, if it
>> fails in order to avoid NULL pointer dereference.
>>
>> Fixes: 5d171050e28f ("sparc64: vcc: Enable VCC port probe and removal")
>> Signed-off-by: Yi Yang <yiyang13@huawei.com>
>> ---
>> drivers/tty/vcc.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>>
>> diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
>> index a39ed981bfd3..420d334f6077 100644
>> --- a/drivers/tty/vcc.c
>> +++ b/drivers/tty/vcc.c
>> @@ -579,6 +579,10 @@ static int vcc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
>> return -ENOMEM;
>>
>> name = kstrdup(dev_name(&vdev->dev), GFP_KERNEL);
>> + if (!name) {
>> + kfree(port);
>> + return -ENOMEM;
>
> Please just add another goto target later in the function like the rest
> of the error paths follow.
Ok, i will send v2 patch for this issue.
>
> And how did you test this patch?
>
I use crosstool-ng build sparc arch for open CONFIG_VCC.
> thanks,
>
> greg k-h
> .
>
--
thanks for your advice.
Yi Yang
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] tty: vcc: Add check for kstrdup() in vcc_probe()
2023-09-04 3:45 ` yiyang (D)
@ 2023-09-04 6:17 ` Greg KH
2023-09-04 6:40 ` yiyang (D)
0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2023-09-04 6:17 UTC (permalink / raw)
To: yiyang (D); +Cc: davem, jirislaby, jag.raman, linux-serial
On Mon, Sep 04, 2023 at 11:45:11AM +0800, yiyang (D) wrote:
> On 2023/9/3 18:49, Greg KH wrote:
> > On Sun, Sep 03, 2023 at 06:13:22PM +0800, Yi Yang wrote:
> > > Add check for the return value of kstrdup() and return the error, if it
> > > fails in order to avoid NULL pointer dereference.
> > >
> > > Fixes: 5d171050e28f ("sparc64: vcc: Enable VCC port probe and removal")
> > > Signed-off-by: Yi Yang <yiyang13@huawei.com>
> > > ---
> > > drivers/tty/vcc.c | 9 +++++++++
> > > 1 file changed, 9 insertions(+)
> > >
> > > diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
> > > index a39ed981bfd3..420d334f6077 100644
> > > --- a/drivers/tty/vcc.c
> > > +++ b/drivers/tty/vcc.c
> > > @@ -579,6 +579,10 @@ static int vcc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
> > > return -ENOMEM;
> > > name = kstrdup(dev_name(&vdev->dev), GFP_KERNEL);
> > > + if (!name) {
> > > + kfree(port);
> > > + return -ENOMEM;
> >
> > Please just add another goto target later in the function like the rest
> > of the error paths follow.
> Ok, i will send v2 patch for this issue.
> >
> > And how did you test this patch?
> >
> I use crosstool-ng build sparc arch for open CONFIG_VCC.
That is build-testing, how did you functionally test that this works
properly?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] tty: vcc: Add check for kstrdup() in vcc_probe()
2023-09-04 6:17 ` Greg KH
@ 2023-09-04 6:40 ` yiyang (D)
0 siblings, 0 replies; 5+ messages in thread
From: yiyang (D) @ 2023-09-04 6:40 UTC (permalink / raw)
To: Greg KH; +Cc: davem, jirislaby, jag.raman, linux-serial
On 2023/9/4 14:17, Greg KH wrote:
> On Mon, Sep 04, 2023 at 11:45:11AM +0800, yiyang (D) wrote:
>> On 2023/9/3 18:49, Greg KH wrote:
>>> On Sun, Sep 03, 2023 at 06:13:22PM +0800, Yi Yang wrote:
>>>> Add check for the return value of kstrdup() and return the error, if it
>>>> fails in order to avoid NULL pointer dereference.
>>>>
>>>> Fixes: 5d171050e28f ("sparc64: vcc: Enable VCC port probe and removal")
>>>> Signed-off-by: Yi Yang <yiyang13@huawei.com>
>>>> ---
>>>> drivers/tty/vcc.c | 9 +++++++++
>>>> 1 file changed, 9 insertions(+)
>>>>
>>>> diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
>>>> index a39ed981bfd3..420d334f6077 100644
>>>> --- a/drivers/tty/vcc.c
>>>> +++ b/drivers/tty/vcc.c
>>>> @@ -579,6 +579,10 @@ static int vcc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
>>>> return -ENOMEM;
>>>> name = kstrdup(dev_name(&vdev->dev), GFP_KERNEL);
>>>> + if (!name) {
>>>> + kfree(port);
>>>> + return -ENOMEM;
>>>
>>> Please just add another goto target later in the function like the rest
>>> of the error paths follow.
>> Ok, i will send v2 patch for this issue.
>>>
>>> And how did you test this patch?
>>>
>> I use crosstool-ng build sparc arch for open CONFIG_VCC.
>
> That is build-testing, how did you functionally test that this works
> properly?
>
Sorry, I only passed the build test, and did not perform the works test
because there was no corresponding hardware.
thanks,
Yi Yang
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-09-04 6:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-03 10:13 [PATCH] tty: vcc: Add check for kstrdup() in vcc_probe() Yi Yang
2023-09-03 10:49 ` Greg KH
2023-09-04 3:45 ` yiyang (D)
2023-09-04 6:17 ` Greg KH
2023-09-04 6:40 ` yiyang (D)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox