New: Missing null check in ast_vhub_init_dev
https://bugzilla.kernel.org/show_bug.cgi?id=219951
Bug ID: 219951
Summary: Missing null check in ast_vhub_init_dev
Product: Drivers
Version: 2.5
Hardware: All
OS: Linux
Status: NEW
Severity: normal
Priority: P3
Component: USB
Assignee: [email protected]
Reporter: [email protected]
Regression: Nousb: gadget: udc: aspeed-vhub: dev.c
Add NULL check in the ast_vhub_init_dev
When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function ast_vhub_init_dev.
A NULL check should be added after the devm_kasprintf call to prevent potential NULL pointer dereference error.
CODE:
struct ast_vhub_dev *d = &vhub->ports[idx].dev;
struct device *parent = &vhub->pdev->dev;
int rc;
d->vhub = vhub;
d->index = idx;
d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d", idx+1);
d->regs = vhub->regs + 0x100 + 0x10 * idx;
ast_vhub_init_ep0(vhub, &d->ep0, d);Signature · 4 lines
You may reply to this email to add a comment. You are receiving this mail because: You are watching the assignee of the bug.
Quoted 5 lines · On Fri, Mar 28, 2025 at 11:15:22AM +0000, [email protected] wrote:
When
devm_kasprintf()fails, it returns a NULL pointer. However, this return value is not properly checked in the functionast_vhub_init_dev.A NULL check should be added after the
devm_kasprintfcall to prevent potential NULL pointer dereference error.
Please submit a patch for this if you feel it needs to be fixed up.
thanks,
greg k-h
[Bug 219951] Missing null check in ast_vhub_init_dev
In reply to [email protected]https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #1 from Greg Kroah-Hartman ([email protected]) ---
Quoted 6 lines · On Fri, Mar 28, 2025 at 11:15:22AM +0000, [email protected] wrote:
When
devm_kasprintf()fails, it returns a NULL pointer. However, this return value is not properly checked in the functionast_vhub_init_dev.A NULL check should be added after the
devm_kasprintfcall to prevent potential
NULL pointer dereference error.
Please submit a patch for this if you feel it needs to be fixed up.
thanks,
greg k-h
Signature · 4 lines
You may reply to this email to add a comment. You are receiving this mail because: You are watching the assignee of the bug.
[Bug 219951] Missing null check in ast_vhub_init_dev
In reply to [email protected]https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #2 from henry ([email protected]) ---
We should first check devm_kasprintf() before setting d->vhub and d->index, so that if allocation fails, the d struct remains in a clean state.
Patch code:
int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx) {
struct ast_vhub_dev *d = &vhub->ports[idx].dev; struct device *parent = &vhub->pdev->dev;
int rc;
/* First allocate the name (before modifying d->vhub/index) */ d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d", idx + 1); if (!d->name)
return -ENOMEM;
/* Now safe to set vhub and index */d->vhub = vhub;d->index = idx;d->regs = vhub->regs + 0x100 + 0x10 * idx;
ast_vhub_init_ep0(vhub, &d->ep0, d);
Quoted 24 lines · <[email protected]> 于2025年3月28日周五 19:27写道:
https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #1 from Greg Kroah-Hartman ([email protected]) ---
Quoted 1 line · On Fri, Mar 28, 2025 at 11:15:22AM +0000, [email protected] wrote:
When
devm_kasprintf()fails, it returns a NULL pointer. However, thisreturn
Quoted 5 lines
value is not properly checked in the function
ast_vhub_init_dev.A NULL check should be added after the
devm_kasprintfcall to prevent potential
NULL pointer dereference error.Please submit a patch for this if you feel it needs to be fixed up.
thanks,
greg k-h
--
You may reply to this email to add a comment.You are receiving this mail because:
You reported the bug.
Signature · 4 lines
You may reply to this email to add a comment. You are receiving this mail because: You are watching the assignee of the bug.
[Bug 219951] Missing null check in ast_vhub_init_dev
In reply to [email protected]https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #3 from henry ([email protected]) --- This is patch file.
Quoted 51 lines · henry martin <[email protected]> 于2025年3月28日周五 20:41写道:
We should first check
devm_kasprintf()before settingd->vhubandd->index, so that if allocation fails, the d struct remains in a clean state.Patch code:
intast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx){
structast_vhub_dev*d = &vhub->ports[idx].dev; struct device *parent =&vhub->pdev->dev;
int rc;/* First allocate the name (before modifying d->vhub/index) */
d->name=devm_kasprintf(parent, GFP_KERNEL, "port%d", idx + 1); if (!d->name)
return-ENOMEM;/* Now safe to set vhub and index */
d->vhub= vhub;d->index= idx;d->regs=vhub->regs+0x100+0x10* idx;
ast_vhub_init_ep0(vhub, &d->ep0, d);Quoted 24 lines · <[email protected]> 于2025年3月28日周五 19:27写道:
https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #1 from Greg Kroah-Hartman ([email protected]) ---
Quoted 1 line · On Fri, Mar 28, 2025 at 11:15:22AM +0000, [email protected] wrote:
When
devm_kasprintf()fails, it returns a NULL pointer. However, thisreturn
Quoted 5 lines
value is not properly checked in the function
ast_vhub_init_dev.A NULL check should be added after the
devm_kasprintfcall to prevent potential
NULL pointer dereference error.Please submit a patch for this if you feel it needs to be fixed up.
thanks,
greg k-h
--
You may reply to this email to add a comment.You are receiving this mail because:
You reported the bug.
Signature · 4 lines
You may reply to this email to add a comment. You are receiving this mail because: You are watching the assignee of the bug.
Re: [Bug 219951] Missing null check in ast_vhub_init_dev
Quoted 4 lines · On Fri, Mar 28, 2025 at 01:14:23PM +0000, [email protected] wrote:
https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #3 from henry ([email protected]) --- This is patch file.
Please read the kernel documentation for how to submit a patch in a way we can accept it. We can't take it through bugzilla, sorry.
[Bug 219951] Missing null check in ast_vhub_init_dev
In reply to [email protected]https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #4 from Greg Kroah-Hartman ([email protected]) ---
Quoted 4 lines · On Fri, Mar 28, 2025 at 01:14:23PM +0000, [email protected] wrote:
https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #3 from henry ([email protected]) --- This is patch file.
Please read the kernel documentation for how to submit a patch in a way we can accept it. We can't take it through bugzilla, sorry.
Signature · 4 lines
You may reply to this email to add a comment. You are receiving this mail because: You are watching the assignee of the bug.
[Bug 219951] Missing null check in ast_vhub_init_dev
In reply to [email protected]https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #5 from henry ([email protected]) ---
Thank you for your feedback. I've now properly submitted this patch via email to the relevant mailing lists with you in CC, as required by the kernel submission process.
Please let me know if there are any issues with the submission format or content that I should address. I'm happy to make any necessary adjustments.
Quoted 18 lines · <[email protected]> 于2025年3月29日周六 05:08写道:
https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #4 from Greg Kroah-Hartman ([email protected]) ---
Quoted 4 lines · On Fri, Mar 28, 2025 at 01:14:23PM +0000, [email protected] wrote:
https://bugzilla.kernel.org/show_bug.cgi?id=219951
--- Comment #3 from henry ([email protected]) --- This is patch file.
Please read the kernel documentation for how to submit a patch in a way we can accept it. We can't take it through bugzilla, sorry.
--
You may reply to this email to add a comment.You are receiving this mail because:
You reported the bug.
Signature · 4 lines
You may reply to this email to add a comment. You are receiving this mail because: You are watching the assignee of the bug.