PROBLEM: there exists a wrong return value of function mkiss_open()
Subsystems (2)
I don't know how many people care about hamradio, but the report that mkiss_open() returns success even when register_netdev() fails seems entirely true. The email was just not sent to the right people..
Linus
Quoted 65 lines · RUC_Soft_Sec
Summary:
there exists a wrong return value of functionmkiss_open(). It's a
theoretical problem. we use static analysis method to detect this bug. Bug Description:In function
mkiss_open()atdrivers/net/hamradio/mkiss.c:726, the call toregister_netdev()in line 765 may return a negative error code, and thus functionmkiss_open()will return the value of variable err. And, the functionmkiss_open()will return 0 at last when it runs well. However, when the call toregister_netdev()in line 765 return a negative error code, the value of err is 0. So the functionmkiss_open()will return 0 to its caller functions when it runs error because of the failing call toregister_netdev(), leading to a wrong return value of functionmkiss_open(). The related code snippets inmkiss_open()is as following.mkiss_open@@drivers/net/hamradio/mkiss.c:726
726static intmkiss_open(struct tty_struct *tty)727{ ... 761 if ((err = ax_open(ax->dev))) { 762 goto out_free_netdev; 763 } 764 765 if (register_netdev(dev)) 766 goto out_free_buffers; ...800out_free_buffers:
801kfree(ax->rbuff);
802kfree(ax->xbuff);
803
804out_free_netdev:
805free_netdev(dev);
806
807out:
808 return err;
809}Generally, when the call to
register_netdev()fails, the return value of caller functions should be different from another return value set when the call toregister_netdev()succeeds, like the following codes in another file.com90io_found@@drivers/net/arcnet/com90io.c:234
234static int__initcom90io_found(struct net_device *dev)235{ ... 268 err = register_netdev(dev); 269 if (err) { 270 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG); 271 free_irq(dev->irq, dev); 272 release_region(dev->base_addr, ARCNET_TOTAL_SIZE); 273 return err;274 }
275
276 BUGMSG(D_NORMAL, "COM90IO: station %02Xh found at %03lXh, IRQ
%d.\n",
277 dev->dev_addr[0],dev->base_addr,dev->irq);
278
279 return 0;
280}Kernel version:
3.19.1
PATCH 1/1 hamradio/kiss: missing error code in mkiss_open()
If register_netdev() fails we return success but we should return an error code instead.
drivers/net/hamradio/mkiss.c +2 -1
@@ -732,7 +732,8 @@ static int mkiss_open(struct tty_struct *tty) goto out_free_netdev; } -if (register_netdev (dev)) + err =register_netdev (dev); +if (err) goto out_free_buffers;/* after register_netdev() - because else printk smashes the kernel */
Re: [patch] hamradio/kiss: missing error code in mkiss_open()
Quoted 5 lines · Dan Carpenter
If
register_netdev()fails we return success but we should return an error code instead.Reported-by RUC_Soft_Sec <[email protected]>Signed-off-by Dan Carpenter <[email protected]>
I have also sent a similar one:
https://patchwork.ozlabs.org/patch/505758/
David Miller
maintainerRe: [patch] hamradio/kiss: missing error code in mkiss_open()
In reply to Dan CarpenterFrom: Dan Carpenter <[email protected]>
Date: Tue, 11 Aug 2015 00:39:22 +0300
Quoted 5 lines
If
register_netdev()fails we return success but we should return an error code instead.Reported-by RUC_Soft_Sec <[email protected]>Signed-off-by Dan Carpenter <[email protected]>
I just applied another patch which fixes this earlier.