From: Pavel Skripkin <paskripkin@gmail.com>
To: syzbot <syzbot+398e7dc692ddbbb4cfec@syzkaller.appspotmail.com>,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
rafael@kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] memory leak in __mdiobus_register
Date: Mon, 27 Sep 2021 02:27:33 +0300 [thread overview]
Message-ID: <35d0ddc1-41cd-16fb-41ea-5529d19c04d2@gmail.com> (raw)
In-Reply-To: <00000000000069acee05ccdbe5a7@google.com>
[-- Attachment #1: Type: text/plain, Size: 1204 bytes --]
On 9/26/21 04:28, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: d9fb678414c0 Merge tag 'afs-fixes-20210913' of git://git.k..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=131c754b300000
> kernel config: https://syzkaller.appspot.com/x/.config?x=f0de362a1f17687e
> dashboard link: https://syzkaller.appspot.com/bug?extid=398e7dc692ddbbb4cfec
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=145650d1300000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=105ccde7300000
>
Looks like MDIOBUS_ALLOCATED indicated 2 states:
1. Bus is only allocated
2. Bus allocated and __mdiobus_register() fails, but
device_register() was called
These 2 cases should be handled separately, i.e. we need to call
put_device() if device_register() was called.
To handle this situation we can add new state MDIOBUS_DEV_REGISTERED and
handle it properly
Just for thoughts and syzbot testing
#syz test
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
With regards,
Pavel Skripkin
[-- Attachment #2: ph --]
[-- Type: text/plain, Size: 998 bytes --]
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 53f034fc2ef7..ed764638b449 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -540,6 +540,8 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
return -EINVAL;
}
+ bus->state = MDIOBUS_DEV_REGISTERED;
+
mutex_init(&bus->mdio_lock);
mutex_init(&bus->shared_lock);
@@ -647,7 +649,7 @@ void mdiobus_free(struct mii_bus *bus)
return;
}
- BUG_ON(bus->state != MDIOBUS_UNREGISTERED);
+ BUG_ON(bus->state != MDIOBUS_UNREGISTERED && bus->state != MDIOBUS_DEV_REGISTERED);
bus->state = MDIOBUS_RELEASED;
put_device(&bus->dev);
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 736e1d1a47c4..41d2ccdacd5e 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -343,6 +343,7 @@ struct mii_bus {
MDIOBUS_REGISTERED,
MDIOBUS_UNREGISTERED,
MDIOBUS_RELEASED,
+ MDIOBUS_DEV_REGISTERED,
} state;
/** @dev: Kernel device representation */
next prev parent reply other threads:[~2021-09-26 23:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-26 1:28 [syzbot] memory leak in __mdiobus_register syzbot
2021-09-26 23:27 ` Pavel Skripkin [this message]
2021-09-26 23:44 ` syzbot
2021-09-28 7:42 ` Dongliang Mu
2021-09-28 8:15 ` Pavel Skripkin
2021-09-28 15:39 ` Dongliang Mu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=35d0ddc1-41cd-16fb-41ea-5529d19c04d2@gmail.com \
--to=paskripkin@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=syzbot+398e7dc692ddbbb4cfec@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox