Re: Re: [BUG] net/ppp: A use after free in ppp_unregister_channe
Tom Parkin <[email protected]>
| Newsgroups | gmane.linux.ppp,gmane.linux.network,gmane.linux.kernel |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Mar 12, 2021 at 22:47:53 +0800, [email protected] wrote: > > > > > -----原始邮件----- > > 发件人: "Tom Parkin" <[email protected]> > > 发送时间: 2021-03-12 18:12:58 (星期五) > > 收件人: [email protected] > > 抄送: [email protected], [email protected], [email protected], [email protected], [email protected] > > 主题: 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, [email protected] 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.
signature.asc
(application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEsUkgyDzMwrj81nq0lIwGZQq6i9AFAmBPL54ACgkQlIwGZQq6 i9AyuggAr4h5Rb/mILMnt6v4Gc3RZ9yannFHesdENxrWQxNjeEvMT7av2t77lqQJ DR+DBxMluf+gcEmEIPHgwx0OeiNCY8CB9tE1HXLG/r8pVnjqJyL4GjQO8BdaSRPt s0odEAJXhlxcwrBBVXYwkWdILbDIF6cZRyjc3lX1WNsNNSumhMl2XSZ8rxYz03Gi DnDoM8ODo6zhKMMNSaAJv8p7WhFEUpdM3KcUJZbRmZaf8fodSeTok45L2lItSMp8 l2FSVWW8Laexx/wjX5HTru5SffQze6je3qJY5fG+BTMvpW97/PHou9Rn+HrAc7RM Is5uP7fllO/TSXSiHxAb9MJKkGDiJw== =GwFI -----END PGP SIGNATURE-----