From: Cong Wang <hidden> Date: 2018-01-15 19:37:35
tfile->tun could be detached before we close the tun fd,
via tun_detach_all(), so it should not be used to check for
tfile->tx_array.
As Jason suggested, we probably have to clean it up
unconditionally both in __tun_deatch() and tun_detach_all(),
but this requires to check if it is initialized or not.
Currently skb_array_cleanup() doesn't have such a check,
so I check it in the caller and introduce a helper function,
it is a bit ugly but we can always improve it in net-next.
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Fixes: 1576d9860599 ("tun: switch to use skb array for tx")
Cc: Jason Wang <redacted>
Signed-off-by: Cong Wang <redacted>
---
drivers/net/tun.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
From: Jason Wang <hidden> Date: 2018-01-16 05:46:44
On 2018年01月16日 03:37, Cong Wang wrote:
quoted hunk
tfile->tun could be detached before we close the tun fd,
via tun_detach_all(), so it should not be used to check for
tfile->tx_array.
As Jason suggested, we probably have to clean it up
unconditionally both in __tun_deatch() and tun_detach_all(),
but this requires to check if it is initialized or not.
Currently skb_array_cleanup() doesn't have such a check,
so I check it in the caller and introduce a helper function,
it is a bit ugly but we can always improve it in net-next.
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Fixes: 1576d9860599 ("tun: switch to use skb array for tx")
Cc: Jason Wang <redacted>
Signed-off-by: Cong Wang <redacted>
---
drivers/net/tun.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
From: Jason Wang <hidden> Date: 2018-01-16 06:00:56
On 2018年01月16日 13:49, Cong Wang wrote:
On Mon, Jan 15, 2018 at 9:46 PM, Jason Wang [off-list ref] wrote:
quoted
I think then you don't even need the memset trick since we are sure it has
been implemented?
It doesn't look like sk_alloc() zero's the memory of tfile.
Typo, for "implemented" I mean "initialized".
I mean we can leave __tun_detach() as is, and just add the cleanup to
tun_detach_all(). This is because in both cases, we're sure skb array
has been initialized before.
Thanks
From: Cong Wang <hidden> Date: 2018-01-16 06:07:58
On Mon, Jan 15, 2018 at 10:00 PM, Jason Wang [off-list ref] wrote:
I mean we can leave __tun_detach() as is, and just add the cleanup to
tun_detach_all(). This is because in both cases, we're sure skb array has
been initialized before.
Oh, I thought the same before sending v3, but I believe it is easier to
understand 'if (tfile->tx_array.ring.queue)' than 'if (tun)', because tx_array
only depends on itself rather tfile->tun in this way.
From: Jason Wang <hidden> Date: 2018-01-16 06:12:58
On 2018年01月16日 14:07, Cong Wang wrote:
On Mon, Jan 15, 2018 at 10:00 PM, Jason Wang [off-list ref] wrote:
quoted
I mean we can leave __tun_detach() as is, and just add the cleanup to
tun_detach_all(). This is because in both cases, we're sure skb array has
been initialized before.
Oh, I thought the same before sending v3, but I believe it is easier to
understand 'if (tfile->tx_array.ring.queue)' than 'if (tun)', because tx_array
only depends on itself rather tfile->tun in this way.
Maybe just add a comment to explain in __tun_detach(), it avoids
memset() anyway.
Thanks
From: Cong Wang <hidden> Date: 2018-01-16 06:34:01
On Mon, Jan 15, 2018 at 10:12 PM, Jason Wang [off-list ref] wrote:
On 2018年01月16日 14:07, Cong Wang wrote:
quoted
On Mon, Jan 15, 2018 at 10:00 PM, Jason Wang [off-list ref] wrote:
quoted
I mean we can leave __tun_detach() as is, and just add the cleanup to
tun_detach_all(). This is because in both cases, we're sure skb array has
been initialized before.
Oh, I thought the same before sending v3, but I believe it is easier to
understand 'if (tfile->tx_array.ring.queue)' than 'if (tun)', because
tx_array
only depends on itself rather tfile->tun in this way.
Maybe just add a comment to explain in __tun_detach(), it avoids memset()
anyway.
But __tun_detach(true) is not a hot path, a memset() doesn't harm anything.
From: Jason Wang <hidden> Date: 2018-01-16 06:37:42
On 2018年01月16日 14:33, Cong Wang wrote:
On Mon, Jan 15, 2018 at 10:12 PM, Jason Wang [off-list ref] wrote:
quoted
On 2018年01月16日 14:07, Cong Wang wrote:
quoted
On Mon, Jan 15, 2018 at 10:00 PM, Jason Wang [off-list ref] wrote:
quoted
I mean we can leave __tun_detach() as is, and just add the cleanup to
tun_detach_all(). This is because in both cases, we're sure skb array has
been initialized before.
Oh, I thought the same before sending v3, but I believe it is easier to
understand 'if (tfile->tx_array.ring.queue)' than 'if (tun)', because
tx_array
only depends on itself rather tfile->tun in this way.
Maybe just add a comment to explain in __tun_detach(), it avoids memset()
anyway.
But __tun_detach(true) is not a hot path, a memset() doesn't harm anything.
Yes, but it looks more more like a workaround or trick to me.
Thanks
From: Cong Wang <hidden> Date: 2018-01-16 06:49:45
On Mon, Jan 15, 2018 at 10:37 PM, Jason Wang [off-list ref] wrote:
On 2018年01月16日 14:33, Cong Wang wrote:
quoted
But __tun_detach(true) is not a hot path, a memset() doesn't harm
anything.
Yes, but it looks more more like a workaround or trick to me.
I'd blame skb_array API for this. ;) Ideally, skb_array_cleanup()
should take care of everything I put in tun_cleanup_tx_array().
As I mentioned in changelog, we can always improve it in
-net-next, so I don't want to bother it for -net.