* [BUG] net/ppp: A use after free in ppp_unregister_channe @ 2021-03-11 12:34 lyl2019 2021-03-12 10:12 ` Tom Parkin 2021-03-15 11:50 ` Guillaume Nault 0 siblings, 2 replies; 8+ messages in thread From: lyl2019 @ 2021-03-11 12:34 UTC (permalink / raw) To: paulus, davem; +Cc: linux-ppp, netdev, linux-kernel File: drivers/net/ppp/ppp_generic.c In ppp_unregister_channel, pch could be freed in ppp_unbridge_channels() but after that pch is still in use. Inside the function ppp_unbridge_channels, if "pchbb == pch" is true and then pch will be freed. I checked the commit history and found that this problem is introduced from 4cf476ced45d7 ("ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls"). I have no idea about how to generate a suitable patch, sorry. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [BUG] net/ppp: A use after free in ppp_unregister_channe 2021-03-11 12:34 [BUG] net/ppp: A use after free in ppp_unregister_channe lyl2019 @ 2021-03-12 10:12 ` Tom Parkin 2021-03-12 14:47 ` lyl2019 2021-03-15 12:04 ` Guillaume Nault 2021-03-15 11:50 ` Guillaume Nault 1 sibling, 2 replies; 8+ messages in thread From: Tom Parkin @ 2021-03-12 10:12 UTC (permalink / raw) To: lyl2019; +Cc: paulus, davem, linux-ppp, netdev, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1239 bytes --] Thanks for the report! On Thu, Mar 11, 2021 at 20:34:44 +0800, lyl2019@mail.ustc.edu.cn wrote: > File: drivers/net/ppp/ppp_generic.c > > In ppp_unregister_channel, pch could be freed in ppp_unbridge_channels() > but after that pch is still in use. Inside the function ppp_unbridge_channels, > if "pchbb == pch" is true and then pch will be freed. Do you have a way to reproduce a use-after-free scenario? From static analysis I'm not sure how pch would be freed in ppp_unbridge_channels when called via. ppp_unregister_channel. In theory (at least!) the caller of ppp_register_net_channel holds a reference on struct channel which ppp_unregister_channel drops. Each channel in a bridged pair holds a reference on the other. Hence on return from ppp_unbridge_channels, the channel should not have been freed (in this code path) because the ppp_register_net_channel reference has not yet been dropped. Maybe there is an issue with the reference counting or a race of some sort? > I checked the commit history and found that this problem is introduced from > 4cf476ced45d7 ("ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls"). > > I have no idea about how to generate a suitable patch, sorry. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe 2021-03-12 10:12 ` Tom Parkin @ 2021-03-12 14:47 ` lyl2019 2021-03-15 9:57 ` Tom Parkin 2021-03-15 12:18 ` Guillaume Nault 2021-03-15 12:04 ` Guillaume Nault 1 sibling, 2 replies; 8+ messages in thread From: lyl2019 @ 2021-03-12 14:47 UTC (permalink / raw) To: Tom Parkin; +Cc: paulus, davem, linux-ppp, netdev, linux-kernel > -----原始邮件----- > 发件人: "Tom Parkin" <tparkin@katalix.com> > 发送时间: 2021-03-12 18:12:58 (星期五) > 收件人: lyl2019@mail.ustc.edu.cn > 抄送: paulus@samba.org, davem@davemloft.net, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org > 主题: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe > > Thanks for the report! > > On Thu, Mar 11, 2021 at 20:34:44 +0800, lyl2019@mail.ustc.edu.cn wrote: > > File: drivers/net/ppp/ppp_generic.c > > > > In ppp_unregister_channel, pch could be freed in ppp_unbridge_channels() > > but after that pch is still in use. Inside the function ppp_unbridge_channels, > > if "pchbb == pch" is true and then pch will be freed. > > Do you have a way to reproduce a use-after-free scenario? > > From static analysis I'm not sure how pch would be freed in > ppp_unbridge_channels when called via. ppp_unregister_channel. > > In theory (at least!) the caller of ppp_register_net_channel holds > a reference on struct channel which ppp_unregister_channel drops. > > Each channel in a bridged pair holds a reference on the other. > > Hence on return from ppp_unbridge_channels, the channel should not have > been freed (in this code path) because the ppp_register_net_channel > reference has not yet been dropped. > > Maybe there is an issue with the reference counting or a race of some > sort? > > > I checked the commit history and found that this problem is introduced from > > 4cf476ced45d7 ("ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls"). > > > > I have no idea about how to generate a suitable patch, sorry. This issue was reported by a path-sensitive static analyzer developed by our Lab, thus i have not a crash or bug log. As the return type of ppp_unbridge_channels() is a int, can we return a value to inform caller that the channel is freed? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe 2021-03-12 14:47 ` lyl2019 @ 2021-03-15 9:57 ` Tom Parkin 2021-03-15 12:18 ` Guillaume Nault 1 sibling, 0 replies; 8+ messages in thread From: Tom Parkin @ 2021-03-15 9:57 UTC (permalink / raw) To: lyl2019; +Cc: paulus, davem, linux-ppp, netdev, linux-kernel [-- Attachment #1: Type: text/plain, Size: 2631 bytes --] On Fri, Mar 12, 2021 at 22:47:53 +0800, lyl2019@mail.ustc.edu.cn wrote: > > > > > -----原始邮件----- > > 发件人: "Tom Parkin" <tparkin@katalix.com> > > 发送时间: 2021-03-12 18:12:58 (星期五) > > 收件人: lyl2019@mail.ustc.edu.cn > > 抄送: paulus@samba.org, davem@davemloft.net, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org > > 主题: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe > > > > Thanks for the report! > > > > On Thu, Mar 11, 2021 at 20:34:44 +0800, lyl2019@mail.ustc.edu.cn wrote: > > > File: drivers/net/ppp/ppp_generic.c > > > > > > In ppp_unregister_channel, pch could be freed in ppp_unbridge_channels() > > > but after that pch is still in use. Inside the function ppp_unbridge_channels, > > > if "pchbb == pch" is true and then pch will be freed. > > > > Do you have a way to reproduce a use-after-free scenario? > > > > From static analysis I'm not sure how pch would be freed in > > ppp_unbridge_channels when called via. ppp_unregister_channel. > > > > In theory (at least!) the caller of ppp_register_net_channel holds > > a reference on struct channel which ppp_unregister_channel drops. > > > > Each channel in a bridged pair holds a reference on the other. > > > > Hence on return from ppp_unbridge_channels, the channel should not have > > been freed (in this code path) because the ppp_register_net_channel > > reference has not yet been dropped. > > > > Maybe there is an issue with the reference counting or a race of some > > sort? > > > > > I checked the commit history and found that this problem is introduced from > > > 4cf476ced45d7 ("ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls"). > > > > > > I have no idea about how to generate a suitable patch, sorry. > > This issue was reported by a path-sensitive static analyzer developed by our Lab, > thus i have not a crash or bug log. Does the analyzer report the sequence of events that lead to a possible use-after-free? Is it starting from the assumption that ppp_unbridge_channels is called with pch->file.refcnt == 1? > As the return type of ppp_unbridge_channels() is a int, can we return a value to > inform caller that the channel is freed? If ppp_unbridge_channels frees the channel in the ppp_unregister_channel call path, that implies that ppp_unregister_channel is called when only the bridge is keeping the channel alive. So the caller is attempting to drop a reference it doesn't in fact have. It might be preferable to defensively code against that possibility of course. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe 2021-03-12 14:47 ` lyl2019 2021-03-15 9:57 ` Tom Parkin @ 2021-03-15 12:18 ` Guillaume Nault 2021-03-15 16:58 ` Tom Parkin 1 sibling, 1 reply; 8+ messages in thread From: Guillaume Nault @ 2021-03-15 12:18 UTC (permalink / raw) To: lyl2019; +Cc: Tom Parkin, paulus, davem, linux-ppp, netdev, linux-kernel On Fri, Mar 12, 2021 at 10:47:53PM +0800, lyl2019@mail.ustc.edu.cn wrote: > > > > > -----原始邮件----- > > 发件人: "Tom Parkin" <tparkin@katalix.com> > > 发送时间: 2021-03-12 18:12:58 (星期五) > > 收件人: lyl2019@mail.ustc.edu.cn > > 抄送: paulus@samba.org, davem@davemloft.net, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org > > 主题: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe > > > > Thanks for the report! > > > > On Thu, Mar 11, 2021 at 20:34:44 +0800, lyl2019@mail.ustc.edu.cn wrote: > > > File: drivers/net/ppp/ppp_generic.c > > > > > > In ppp_unregister_channel, pch could be freed in ppp_unbridge_channels() > > > but after that pch is still in use. Inside the function ppp_unbridge_channels, > > > if "pchbb == pch" is true and then pch will be freed. > > > > Do you have a way to reproduce a use-after-free scenario? > > > > From static analysis I'm not sure how pch would be freed in > > ppp_unbridge_channels when called via. ppp_unregister_channel. > > > > In theory (at least!) the caller of ppp_register_net_channel holds > > a reference on struct channel which ppp_unregister_channel drops. > > > > Each channel in a bridged pair holds a reference on the other. > > > > Hence on return from ppp_unbridge_channels, the channel should not have > > been freed (in this code path) because the ppp_register_net_channel > > reference has not yet been dropped. > > > > Maybe there is an issue with the reference counting or a race of some > > sort? > > > > > I checked the commit history and found that this problem is introduced from > > > 4cf476ced45d7 ("ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls"). > > > > > > I have no idea about how to generate a suitable patch, sorry. > > This issue was reported by a path-sensitive static analyzer developed by our Lab, > thus i have not a crash or bug log. > > As the return type of ppp_unbridge_channels() is a int, can we return a value to > inform caller that the channel is freed? I don't think this is going to improve anything, as ppp_unregister_channel() couldn't take any corrective action anyway. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe 2021-03-15 12:18 ` Guillaume Nault @ 2021-03-15 16:58 ` Tom Parkin 0 siblings, 0 replies; 8+ messages in thread From: Tom Parkin @ 2021-03-15 16:58 UTC (permalink / raw) To: Guillaume Nault; +Cc: lyl2019, paulus, davem, linux-ppp, netdev, linux-kernel [-- Attachment #1: Type: text/plain, Size: 2494 bytes --] On Mon, Mar 15, 2021 at 13:18:24 +0100, Guillaume Nault wrote: > On Fri, Mar 12, 2021 at 10:47:53PM +0800, lyl2019@mail.ustc.edu.cn wrote: > > > > > > > > > -----原始邮件----- > > > 发件人: "Tom Parkin" <tparkin@katalix.com> > > > 发送时间: 2021-03-12 18:12:58 (星期五) > > > 收件人: lyl2019@mail.ustc.edu.cn > > > 抄送: paulus@samba.org, davem@davemloft.net, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org > > > 主题: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe > > > > > > Thanks for the report! > > > > > > On Thu, Mar 11, 2021 at 20:34:44 +0800, lyl2019@mail.ustc.edu.cn wrote: > > > > File: drivers/net/ppp/ppp_generic.c > > > > > > > > In ppp_unregister_channel, pch could be freed in ppp_unbridge_channels() > > > > but after that pch is still in use. Inside the function ppp_unbridge_channels, > > > > if "pchbb == pch" is true and then pch will be freed. > > > > > > Do you have a way to reproduce a use-after-free scenario? > > > > > > From static analysis I'm not sure how pch would be freed in > > > ppp_unbridge_channels when called via. ppp_unregister_channel. > > > > > > In theory (at least!) the caller of ppp_register_net_channel holds > > > a reference on struct channel which ppp_unregister_channel drops. > > > > > > Each channel in a bridged pair holds a reference on the other. > > > > > > Hence on return from ppp_unbridge_channels, the channel should not have > > > been freed (in this code path) because the ppp_register_net_channel > > > reference has not yet been dropped. > > > > > > Maybe there is an issue with the reference counting or a race of some > > > sort? > > > > > > > I checked the commit history and found that this problem is introduced from > > > > 4cf476ced45d7 ("ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls"). > > > > > > > > I have no idea about how to generate a suitable patch, sorry. > > > > This issue was reported by a path-sensitive static analyzer developed by our Lab, > > thus i have not a crash or bug log. > > > > As the return type of ppp_unbridge_channels() is a int, can we return a value to > > inform caller that the channel is freed? > > I don't think this is going to improve anything, as > ppp_unregister_channel() couldn't take any corrective action anyway. I agree with you to be honest. I think the best ppp_unregister_channel could to is to not access pch again. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [BUG] net/ppp: A use after free in ppp_unregister_channe 2021-03-12 10:12 ` Tom Parkin 2021-03-12 14:47 ` lyl2019 @ 2021-03-15 12:04 ` Guillaume Nault 1 sibling, 0 replies; 8+ messages in thread From: Guillaume Nault @ 2021-03-15 12:04 UTC (permalink / raw) To: Tom Parkin; +Cc: lyl2019, paulus, davem, linux-ppp, netdev, linux-kernel On Fri, Mar 12, 2021 at 10:12:58AM +0000, Tom Parkin wrote: > Thanks for the report! > > On Thu, Mar 11, 2021 at 20:34:44 +0800, lyl2019@mail.ustc.edu.cn wrote: > > File: drivers/net/ppp/ppp_generic.c > > > > In ppp_unregister_channel, pch could be freed in ppp_unbridge_channels() > > but after that pch is still in use. Inside the function ppp_unbridge_channels, > > if "pchbb == pch" is true and then pch will be freed. > > Do you have a way to reproduce a use-after-free scenario? > > From static analysis I'm not sure how pch would be freed in > ppp_unbridge_channels when called via. ppp_unregister_channel. > > In theory (at least!) the caller of ppp_register_net_channel holds > a reference on struct channel which ppp_unregister_channel drops. Agreed: ppp_unregister_channel() is going to drop a refcount from pch in any case. So holding a refcount on pch is a hard requirement for any caller of ppp_unregister_channel(), regardless of the channel bridging code. To lyl2019: Note that this refcount is (unsurprisingly) held by calling ppp_register_net_channel(). ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [BUG] net/ppp: A use after free in ppp_unregister_channe 2021-03-11 12:34 [BUG] net/ppp: A use after free in ppp_unregister_channe lyl2019 2021-03-12 10:12 ` Tom Parkin @ 2021-03-15 11:50 ` Guillaume Nault 1 sibling, 0 replies; 8+ messages in thread From: Guillaume Nault @ 2021-03-15 11:50 UTC (permalink / raw) To: lyl2019; +Cc: paulus, davem, linux-ppp, netdev, linux-kernel, Tom Parkin On Thu, Mar 11, 2021 at 08:34:44PM +0800, lyl2019@mail.ustc.edu.cn wrote: > File: drivers/net/ppp/ppp_generic.c > > In ppp_unregister_channel, pch could be freed in ppp_unbridge_channels() > but after that pch is still in use. Inside the function ppp_unbridge_channels, > if "pchbb == pch" is true and then pch will be freed. No. It's freed only if if the refcount drops to 0. And the caller of ppp_unregister_channel() must hold its own refcount. So ppp_unbridge_channels() is not going to drop the last refcount in this case. > I checked the commit history and found that this problem is introduced from > 4cf476ced45d7 ("ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls"). Next time, please also Cc. the author of the patch. > I have no idea about how to generate a suitable patch, sorry. There's no patch to send as far as I can see. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-03-15 16:58 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-03-11 12:34 [BUG] net/ppp: A use after free in ppp_unregister_channe lyl2019 2021-03-12 10:12 ` Tom Parkin 2021-03-12 14:47 ` lyl2019 2021-03-15 9:57 ` Tom Parkin 2021-03-15 12:18 ` Guillaume Nault 2021-03-15 16:58 ` Tom Parkin 2021-03-15 12:04 ` Guillaume Nault 2021-03-15 11:50 ` Guillaume Nault
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).