The patch titled
Subject: rapidio: add check for rio_add_net() in rio_scan_alloc_net()
has been added to the -mm mm-hotfixes-unstable branch. Its filename is
rapidio-add-check-for-rio_add_net-in-rio_scan_alloc_net.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patche…
This patch will later appear in the mm-hotfixes-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Haoxiang Li <haoxiang_li2024(a)163.com>
Subject: rapidio: add check for rio_add_net() in rio_scan_alloc_net()
Date: Thu, 27 Feb 2025 12:11:31 +0800
The return value of rio_add_net() should be checked. If it fails,
put_device() should be called to free the memory and give up the reference
initialized in rio_add_net().
Link: https://lkml.kernel.org/r/20250227041131.3680761-1-haoxiang_li2024@163.com
Fixes: e6b585ca6e81 ("rapidio: move net allocation into core code")
Signed-off-by: Yang Yingliang <yangyingliang(a)huawei.com>
Signed-off-by: Haoxiang Li <haoxiang_li2024(a)163.com>
Cc: Alexandre Bounine <alex.bou9(a)gmail.com>
Cc: Matt Porter <mporter(a)kernel.crashing.org>
Cc: Dan Carpenter <dan.carpenter(a)linaro.org>
Cc: <stable(a)vger.kernel.org>
Signed-off-by: Andrew Morton <akpm(a)linux-foundation.org>
---
drivers/rapidio/rio-scan.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
--- a/drivers/rapidio/rio-scan.c~rapidio-add-check-for-rio_add_net-in-rio_scan_alloc_net
+++ a/drivers/rapidio/rio-scan.c
@@ -871,7 +871,10 @@ static struct rio_net *rio_scan_alloc_ne
dev_set_name(&net->dev, "rnet_%d", net->id);
net->dev.parent = &mport->dev;
net->dev.release = rio_scan_release_dev;
- rio_add_net(net);
+ if (rio_add_net(net)) {
+ put_device(&net->dev);
+ net = NULL;
+ }
}
return net;
_
Patches currently in -mm which might be from haoxiang_li2024(a)163.com are
m68k-sun3-add-check-for-__pgd_alloc.patch
rapidio-fix-an-api-misues-when-rio_add_net-fails.patch
rapidio-add-check-for-rio_add_net-in-rio_scan_alloc_net.patch
On Wed, Feb 26, 2025 at 02:43:31PM +0100, Andrew Lunn wrote:
> On Tue, Feb 18, 2025 at 12:19:57PM +0000, Qasim Ijaz wrote:
> > On Tue, Feb 18, 2025 at 02:10:08AM +0100, Andrew Lunn wrote:
> > > On Tue, Feb 18, 2025 at 12:24:43AM +0000, Qasim Ijaz wrote:
> > > > In mii_nway_restart() during the line:
> > > >
> > > > bmcr = mii->mdio_read(mii->dev, mii->phy_id, MII_BMCR);
> > > >
> > > > The code attempts to call mii->mdio_read which is ch9200_mdio_read().
> > > >
> > > > ch9200_mdio_read() utilises a local buffer, which is initialised
> > > > with control_read():
> > > >
> > > > unsigned char buff[2];
> > > >
> > > > However buff is conditionally initialised inside control_read():
> > > >
> > > > if (err == size) {
> > > > memcpy(data, buf, size);
> > > > }
> > > >
> > > > If the condition of "err == size" is not met, then buff remains
> > > > uninitialised. Once this happens the uninitialised buff is accessed
> > > > and returned during ch9200_mdio_read():
> > > >
> > > > return (buff[0] | buff[1] << 8);
> > > >
> > > > The problem stems from the fact that ch9200_mdio_read() ignores the
> > > > return value of control_read(), leading to uinit-access of buff.
> > > >
> > > > To fix this we should check the return value of control_read()
> > > > and return early on error.
> > >
> > > What about get_mac_address()?
> > >
> > > If you find a bug, it is a good idea to look around and see if there
> > > are any more instances of the same bug. I could be wrong, but it seems
> > > like get_mac_address() suffers from the same problem?
> >
> > Thank you for the feedback Andrew. I checked get_mac_address() before
> > sending this patch and to me it looks like it does check the return value of
> > control_read(). It accumulates the return value of each control_read() call into
> > rd_mac_len and then checks if it not equal to what is expected (ETH_ALEN which is 6),
> > I believe each call should return 2.
>
> It is unlikely a real device could trigger an issue, but a USB Rubber
> Ducky might be able to. So the question is, are you interested in
> protecting against malicious devices, or just making a static analyser
> happy? Feel free to submit the patch as is.
>
Hi Andrew,
How about an approach similar to the patch for ch9200_mdio_read(), where we immediately check the return value of
each control_read() call in get_mac_address(), and if one fails we stop and return an error right away?
That would ensure we don’t continue if an earlier call fails.
Let me know if you’d like me to submit a patch v2 if this sounds good.
Thanks,
Qasim
> Andrew
>
The patch titled
Subject: rapidio: fix an API misues when rio_add_net() fails
has been added to the -mm mm-hotfixes-unstable branch. Its filename is
rapidio-fix-an-api-misues-when-rio_add_net-fails.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patche…
This patch will later appear in the mm-hotfixes-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Haoxiang Li <haoxiang_li2024(a)163.com>
Subject: rapidio: fix an API misues when rio_add_net() fails
Date: Thu, 27 Feb 2025 15:34:09 +0800
rio_add_net() calls device_register() and fails when device_register()
fails. Thus, put_device() should be used rather than kfree(). Add
"mport->net = NULL;" to avoid a use after free issue.
Link: https://lkml.kernel.org/r/20250227073409.3696854-1-haoxiang_li2024@163.com
Fixes: e8de370188d0 ("rapidio: add mport char device driver")
Signed-off-by: Haoxiang Li <haoxiang_li2024(a)163.com>
Reviewed-by: Dan Carpenter <dan.carpenter(a)linaro.org>
Cc: Alexandre Bounine <alex.bou9(a)gmail.com>
Cc: Matt Porter <mporter(a)kernel.crashing.org>
Cc: <stable(a)vger.kernel.org>
Signed-off-by: Andrew Morton <akpm(a)linux-foundation.org>
---
drivers/rapidio/devices/rio_mport_cdev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--- a/drivers/rapidio/devices/rio_mport_cdev.c~rapidio-fix-an-api-misues-when-rio_add_net-fails
+++ a/drivers/rapidio/devices/rio_mport_cdev.c
@@ -1742,7 +1742,8 @@ static int rio_mport_add_riodev(struct m
err = rio_add_net(net);
if (err) {
rmcd_debug(RDEV, "failed to register net, err=%d", err);
- kfree(net);
+ put_device(&net->dev);
+ mport->net = NULL;
goto cleanup;
}
}
_
Patches currently in -mm which might be from haoxiang_li2024(a)163.com are
m68k-sun3-add-check-for-__pgd_alloc.patch
rapidio-fix-an-api-misues-when-rio_add_net-fails.patch
I discovered a bug that appears in any 6.13 kernel within quemu
but not in any 6.12 kernel.
I use quemu-9.2.2 to run windows10 in it and there I use a program
called sprint-layout-6.0.
This program saves and loads his files via samba,
so I have them on my linux-ext4 disk and not in the
disk-file quemu uses.
It worked for years now and it still works with all 6.12.x
kernels up to now.
But it does not work with any 6.13.x kernel up to date.
The bug shows up when I try to load a file from within this program,
then the emulated windows10 pops up a window with "exeption 8000004".
I do not know what this is trying to tell me, but under any 6.12.x
and older kernels this did not happen.
So I assume a bug in 6.13.x kernel is the cause.
I also reported this to qemu but got now answer up to now.
Any help is welcome, thanks.
--
Best regards
Klaus
I discovered a bug that appears in any 6.13 kernel within quemu
but not in any 6.12 kernel.
I use quemu-9.2.2 to run windows10 in it and there I use a program
called sprint-layout-6.0.
This program saves and loads his files via samba,
so I have them on my linux-ext4 disk and not in the
disk-file quemu uses.
It worked for years now and it still works with all 6.12.x
kernels up to now.
But it does not work with any 6.13.x kernel up to date.
The bug shows up when I try to load a file from within this program,
then the emulated windows10 pops up a window with "exeption 8000004".
I do not know what this is trying to tell me, but under any 6.12.x
and older kernels this did not happen.
So I assume a bug in 6.13.x kernel is the cause.
I also reported this to qemu but got now answer up to now.
Any help is welcome, thanks.
--
Best regards
Klaus
When device_register(&child->dev) failed, we should call put_device()
to explicitly release child->dev.
As comment of device_register() says, 'NOTE: _Never_ directly free
@dev after calling this function, even if it returned an error! Always
use put_device() to give up the reference initialized in this function
instead.'
Found by code review.
Cc: stable(a)vger.kernel.org
Fixes: 4f535093cf8f ("PCI: Put pci_dev in device tree as early as possible")
Signed-off-by: Ma Ke <make24(a)iscas.ac.cn>
---
Changes in v3:
- modified the description as suggestions.
Changes in v2:
- added the bug description about the comment of device_add();
- fixed the patch as suggestions;
- added Cc and Fixes table.
---
drivers/pci/probe.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 2e81ab0f5a25..51b78fcda4eb 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1174,7 +1174,10 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
add_dev:
pci_set_bus_msi_domain(child);
ret = device_register(&child->dev);
- WARN_ON(ret < 0);
+ if (WARN_ON(ret < 0)) {
+ put_device(&child->dev);
+ return NULL;
+ }
pcibios_add_bus(child);
--
2.25.1