From: Dongliang Mu <hidden> Date: 2021-07-14 07:16:11
The current error handling code of hso_create_net_device is
hso_free_net_device, no matter which errors lead to. For example,
WARNING in hso_free_net_device [1].
Fix this by refactoring the error handling code of
hso_create_net_device by handling different errors by different code.
[1] https://syzkaller.appspot.com/bug?id=66eff8d49af1b28370ad342787413e35bbe76efe
Reported-by: syzbot+44d53c7255bb1aea22d2@syzkaller.appspotmail.com
Fixes: 5fcfb6d0bfcd ("hso: fix bailout in error case of probe")
Signed-off-by: Dongliang Mu <redacted>
---
drivers/net/usb/hso.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
From: Dongliang Mu <hidden> Date: 2021-07-14 07:16:23
There are two invocation sites of hso_free_net_device. After
refactoring hso_create_net_device, this parameter is useless.
Remove the bailout in the hso_free_net_device and change the invocation
sites of this function
Signed-off-by: Dongliang Mu <redacted>
---
drivers/net/usb/hso.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
From: Dongliang Mu <hidden> Date: 2021-07-14 07:22:51
On Wed, Jul 14, 2021 at 3:16 PM Dongliang Mu [off-list ref] wrote:
The current error handling code of hso_create_net_device is
hso_free_net_device, no matter which errors lead to. For example,
WARNING in hso_free_net_device [1].
Although there is already a patch for the above bug report, I don't
think it cannot handle all kinds of errors caused in
hso_create_net_device.
So refactoring the error handling code is the only way to fix this issue.
[1] https://syzkaller.appspot.com/text?tag=Patch&x=1188fcc6600000
quoted hunk
Fix this by refactoring the error handling code of
hso_create_net_device by handling different errors by different code.
[1] https://syzkaller.appspot.com/bug?id=66eff8d49af1b28370ad342787413e35bbe76efe
Reported-by: syzbot+44d53c7255bb1aea22d2@syzkaller.appspotmail.com
Fixes: 5fcfb6d0bfcd ("hso: fix bailout in error case of probe")
Signed-off-by: Dongliang Mu <redacted>
---
drivers/net/usb/hso.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
From: Dongliang Mu <hidden> Date: 2021-07-14 08:00:28
On Wed, Jul 14, 2021 at 3:36 PM Dan Carpenter [off-list ref] wrote:
On Wed, Jul 14, 2021 at 03:15:32PM +0800, Dongliang Mu wrote:
quoted
The current error handling code of hso_create_net_device is
hso_free_net_device, no matter which errors lead to. For example,
WARNING in hso_free_net_device [1].
Fix this by refactoring the error handling code of
hso_create_net_device by handling different errors by different code.
[1] https://syzkaller.appspot.com/bug?id=66eff8d49af1b28370ad342787413e35bbe76efe
Reported-by: syzbot+44d53c7255bb1aea22d2@syzkaller.appspotmail.com
Fixes: 5fcfb6d0bfcd ("hso: fix bailout in error case of probe")
Signed-off-by: Dongliang Mu <redacted>
---
drivers/net/usb/hso.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
This is Come From naming style where it says what failed on the line
before. It's not helpful because we can see what failed. What we need
to know is what the goto does.
Use Free the Last thing style. Where you just keep track of the most
recent successful allocation and free it. That way you don't free
things which aren't allocated, you don't double free things, you don't
dereference uninitialized variables or error points. Plus it's a very
simple system where when you're reading code you just have to remember
the last thing that was allocated. Every function must clean up after
itself. Every allocation function needs a free function. The goto
names say the variable that is freed.
That's a good rule to follow. Will change the patch following this rule.
@@ -2523,18 +2525,18 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL); if (!hso_net->mux_bulk_rx_urb_pool[i])- goto exit;+ goto err_mux_bulk_rx; hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE, GFP_KERNEL); if (!hso_net->mux_bulk_rx_buf_pool[i])- goto exit;+ goto err_mux_bulk_rx;
In a loop then how Free the last thing style works is that you free
that partial allocation before the goto. And then do a
while (--i >= 0) {
free_c();
free_b();
free_a();
}
You have told me this rule. But I think the handling of this loop does
not need to be such complicated.
But in this case your code is fine and simple enough. No need to be
dogmatic about style so long as the functions are small.
From: Dan Carpenter <hidden> Date: 2021-07-14 08:33:13
On Wed, Jul 14, 2021 at 03:15:32PM +0800, Dongliang Mu wrote:
quoted hunk
The current error handling code of hso_create_net_device is
hso_free_net_device, no matter which errors lead to. For example,
WARNING in hso_free_net_device [1].
Fix this by refactoring the error handling code of
hso_create_net_device by handling different errors by different code.
[1] https://syzkaller.appspot.com/bug?id=66eff8d49af1b28370ad342787413e35bbe76efe
Reported-by: syzbot+44d53c7255bb1aea22d2@syzkaller.appspotmail.com
Fixes: 5fcfb6d0bfcd ("hso: fix bailout in error case of probe")
Signed-off-by: Dongliang Mu <redacted>
---
drivers/net/usb/hso.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
This is Come From naming style where it says what failed on the line
before. It's not helpful because we can see what failed. What we need
to know is what the goto does.
Use Free the Last thing style. Where you just keep track of the most
recent successful allocation and free it. That way you don't free
things which aren't allocated, you don't double free things, you don't
dereference uninitialized variables or error points. Plus it's a very
simple system where when you're reading code you just have to remember
the last thing that was allocated. Every function must clean up after
itself. Every allocation function needs a free function. The goto
names say the variable that is freed.
goto free_net;
@@ -2523,18 +2525,18 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL); if (!hso_net->mux_bulk_rx_urb_pool[i])- goto exit;+ goto err_mux_bulk_rx; hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE, GFP_KERNEL); if (!hso_net->mux_bulk_rx_buf_pool[i])- goto exit;+ goto err_mux_bulk_rx;
In a loop then how Free the last thing style works is that you free
that partial allocation before the goto. And then do a
while (--i >= 0) {
free_c();
free_b();
free_a();
}
But in this case your code is fine and simple enough. No need to be
dogmatic about style so long as the functions are small.