* tcp: Checking a kmemdup() call in tcp_time_wait()
@ 2019-10-12 14:51 Markus Elfring
2019-10-13 19:45 ` Eric Dumazet
0 siblings, 1 reply; 7+ messages in thread
From: Markus Elfring @ 2019-10-12 14:51 UTC (permalink / raw)
To: netdev, Alexei Starovoitov, Alexey Kuznetsov, Daniel Borkmann,
David S. Miller, Eric Dumazet, Hideaki Yoshifuji,
Martin KaFai Lau, Song Liu, Yonghong Song
Cc: LKML, kernel-janitors, Aditya Pakki, Kangjie Lu, Navid Emamdoost,
Stephen McCamant
Hello,
I tried another script for the semantic patch language out.
This source code analysis approach points out that the implementation
of the function “tcp_time_wait” contains also a call of the function “kmemdup”.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/tcp_minisocks.c?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n306
https://elixir.bootlin.com/linux/v5.4-rc2/source/net/ipv4/tcp_minisocks.c#L306
* Do you find the usage of the macro call “BUG_ON” still appropriate at this place?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n4080
* Is there a need to adjust the error handling here?
Regards,
Markus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tcp: Checking a kmemdup() call in tcp_time_wait()
2019-10-12 14:51 tcp: Checking a kmemdup() call in tcp_time_wait() Markus Elfring
@ 2019-10-13 19:45 ` Eric Dumazet
2019-10-14 6:51 ` Markus Elfring
0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2019-10-13 19:45 UTC (permalink / raw)
To: Markus Elfring, netdev, Alexei Starovoitov, Alexey Kuznetsov,
Daniel Borkmann, David S. Miller, Eric Dumazet,
Hideaki Yoshifuji, Martin KaFai Lau, Song Liu, Yonghong Song
Cc: LKML, kernel-janitors, Aditya Pakki, Kangjie Lu, Navid Emamdoost,
Stephen McCamant
On 10/12/19 7:51 AM, Markus Elfring wrote:
> Hello,
>
> I tried another script for the semantic patch language out.
> This source code analysis approach points out that the implementation
> of the function “tcp_time_wait” contains also a call of the function “kmemdup”.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/tcp_minisocks.c?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n306
> https://elixir.bootlin.com/linux/v5.4-rc2/source/net/ipv4/tcp_minisocks.c#L306
>
> * Do you find the usage of the macro call “BUG_ON” still appropriate at this place?
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n4080
>
> * Is there a need to adjust the error handling here?
Presumably the BUG would trigger if a really disturbing bug happened.
There is no chance a timewait socket could be created with a MD5 key,
if the established socket that is the 'parent' of the timewait
has not a MD5 context itself.
The parent socket only could have MD5 context if tcp_md5sig_pool_populated
could have been set to true.
Once tcp_md5sig_pool_populated is true it can never go back to false.
So the bug here would be that a socket had a successful MD5 context,
and following tcp_alloc_md5sig_pool() would return false.
We can discuss of all BUG() in general, some people simply disable
all of them (cf CONFIG_BUG), but this particular one does not seem
specially bad to me, compared to others.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tcp: Checking a kmemdup() call in tcp_time_wait()
2019-10-13 19:45 ` Eric Dumazet
@ 2019-10-14 6:51 ` Markus Elfring
2019-10-14 12:33 ` Eric Dumazet
0 siblings, 1 reply; 7+ messages in thread
From: Markus Elfring @ 2019-10-14 6:51 UTC (permalink / raw)
To: Eric Dumazet, netdev, Alexei Starovoitov, Alexey Kuznetsov,
Daniel Borkmann, David S. Miller, Eric Dumazet,
Hideaki Yoshifuji, Martin KaFai Lau, Song Liu, Yonghong Song
Cc: LKML, kernel-janitors, Aditya Pakki, Kangjie Lu, Navid Emamdoost,
Stephen McCamant
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/tcp_minisocks.c?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n306
>> https://elixir.bootlin.com/linux/v5.4-rc2/source/net/ipv4/tcp_minisocks.c#L306
…
> Presumably the BUG would trigger if a really disturbing bug happened.
How “buggy” is this place if the function call “kmemdup” failed?
Can an other error reporting approach be nicer here?
Regards,
Markus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tcp: Checking a kmemdup() call in tcp_time_wait()
2019-10-14 6:51 ` Markus Elfring
@ 2019-10-14 12:33 ` Eric Dumazet
2019-10-14 12:50 ` Markus Elfring
0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2019-10-14 12:33 UTC (permalink / raw)
To: Markus Elfring, Eric Dumazet, netdev, Alexei Starovoitov,
Alexey Kuznetsov, Daniel Borkmann, David S. Miller, Eric Dumazet,
Hideaki Yoshifuji, Martin KaFai Lau, Song Liu, Yonghong Song
Cc: LKML, kernel-janitors, Aditya Pakki, Kangjie Lu, Navid Emamdoost,
Stephen McCamant
On 10/13/19 11:51 PM, Markus Elfring wrote:
>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/tcp_minisocks.c?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n306
>>> https://elixir.bootlin.com/linux/v5.4-rc2/source/net/ipv4/tcp_minisocks.c#L306
> …
>> Presumably the BUG would trigger if a really disturbing bug happened.
>
> How “buggy” is this place if the function call “kmemdup” failed?
It is not buggy. The BUG will not trigger.
BUG_ON(tcptw->tw_md5_key && !tcp_alloc_md5sig_pool());
This would be different if we had instead :
BUG_ON(!tcptw->tw_md5_key && !tcp_alloc_md5sig_pool());
>
> Can an other error reporting approach be nicer here?
There is no error reported if kmemdup() has failed.
timewait is best effort.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tcp: Checking a kmemdup() call in tcp_time_wait()
2019-10-14 12:33 ` Eric Dumazet
@ 2019-10-14 12:50 ` Markus Elfring
2019-10-14 13:15 ` Eric Dumazet
0 siblings, 1 reply; 7+ messages in thread
From: Markus Elfring @ 2019-10-14 12:50 UTC (permalink / raw)
To: Eric Dumazet, netdev, Alexei Starovoitov, Alexey Kuznetsov,
Daniel Borkmann, David S. Miller, Eric Dumazet,
Hideaki Yoshifuji, Martin KaFai Lau, Song Liu, Yonghong Song,
kernel-janitors
Cc: LKML, Aditya Pakki, Kangjie Lu, Navid Emamdoost, Stephen McCamant
>>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/tcp_minisocks.c?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n306
>>>> https://elixir.bootlin.com/linux/v5.4-rc2/source/net/ipv4/tcp_minisocks.c#L306
…
>> Can an other error reporting approach be nicer here?
>
> There is no error reported if kmemdup() has failed.
How do data from the Linux allocation failure report fit to this information?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=4f5cafb5cb8471e54afdc9054d973535614f7675#n878
> timewait is best effort.
How do you think about to return an error code like “-ENOMEM” at this place?
Regards,
Markus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tcp: Checking a kmemdup() call in tcp_time_wait()
2019-10-14 12:50 ` Markus Elfring
@ 2019-10-14 13:15 ` Eric Dumazet
2019-10-14 17:19 ` Markus Elfring
0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2019-10-14 13:15 UTC (permalink / raw)
To: Markus Elfring
Cc: Eric Dumazet, netdev, Alexei Starovoitov, Alexey Kuznetsov,
Daniel Borkmann, David S. Miller, Hideaki Yoshifuji,
Martin KaFai Lau, Song Liu, Yonghong Song, kernel-janitors, LKML,
Aditya Pakki, Kangjie Lu, Navid Emamdoost, Stephen McCamant
On Mon, Oct 14, 2019 at 5:51 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/tcp_minisocks.c?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n306
> >>>> https://elixir.bootlin.com/linux/v5.4-rc2/source/net/ipv4/tcp_minisocks.c#L306
> …
>
> >> Can an other error reporting approach be nicer here?
> >
> > There is no error reported if kmemdup() has failed.
>
> How do data from the Linux allocation failure report fit to this information?
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=4f5cafb5cb8471e54afdc9054d973535614f7675#n878
>
This is coding style for newly submitted code.
We do not refactor code to the latest coding style, this would cost a lot.
Especially TCP stack that is quite often changed.
>
> > timewait is best effort.
>
> How do you think about to return an error code like “-ENOMEM” at this place?
tcp_time_wait() is void, the caller won't care. I told you time_wait
is best effort.
What is the problem you want to solve _exactly_ ?
Have you seen a real issue, or should you augment your static analyser
to not complain on :
ptr = kmemdup();
BUG_ON(<any condition>);
(<any condition> being different than (ptr == NULL))
I believe we have enough real bugs to fix.
I would prefer to not spend time arguing for every single BUG() or BUG_ON().
Thank you.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tcp: Checking a kmemdup() call in tcp_time_wait()
2019-10-14 13:15 ` Eric Dumazet
@ 2019-10-14 17:19 ` Markus Elfring
0 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2019-10-14 17:19 UTC (permalink / raw)
To: Eric Dumazet, netdev, kernel-janitors
Cc: Eric Dumazet, Alexei Starovoitov, Alexey Kuznetsov,
Daniel Borkmann, David S. Miller, Hideaki Yoshifuji,
Martin KaFai Lau, Song Liu, Yonghong Song, Aditya Pakki,
Kangjie Lu, Navid Emamdoost, Stephen McCamant, LKML
> This is coding style for newly submitted code.
>
> We do not refactor code to the latest coding style, this would cost a lot.
Were any update candidates left over also in this function implementation?
>> How do you think about to return an error code like “-ENOMEM” at this place?
>
> tcp_time_wait() is void,
Can the function return type be eventually changed?
> the caller won't care.
Will any other software developers (and source code reviewers) start to
care more for unchecked function calls?
> I told you time_wait is best effort.
Can this approach still be improved another bit?
> What is the problem you want to solve _exactly_ ?
I became curious if the software situation can be adjusted around
a possibly ignored return value from a call of a function like kmemdup().
Regards,
Markus
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-10-14 17:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-12 14:51 tcp: Checking a kmemdup() call in tcp_time_wait() Markus Elfring
2019-10-13 19:45 ` Eric Dumazet
2019-10-14 6:51 ` Markus Elfring
2019-10-14 12:33 ` Eric Dumazet
2019-10-14 12:50 ` Markus Elfring
2019-10-14 13:15 ` Eric Dumazet
2019-10-14 17:19 ` Markus Elfring
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).