In ping_unhash(), we should move sock_put(sk) after any possible
access point as the put function may free the object.
Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind")
Signed-off-by: Liang He <redacted>
---
I have found other places containing similar code patterns.
net/ipv4/ping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: David Ahern <dsahern@kernel.org> Date: 2022-09-18 15:30:29
On 9/16/22 4:07 AM, Liang He wrote:
In ping_unhash(), we should move sock_put(sk) after any possible
access point as the put function may free the object.
unhash handlers are called from sk_common_release which still has a
reference on the sock, so not really going to hit a UAF.
I do agree that it does not read correctly to 'put' a reference then
continue using the object. ie., the put should be moved to the end like
you have here. This is more of a tidiness exercise than a need to
backport to stable kernels.
quoted hunk
Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind")
Signed-off-by: Liang He <redacted>
---
I have found other places containing similar code patterns.
net/ipv4/ping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
At 2022-09-18 23:30:21, "David Ahern" [off-list ref] wrote:
On 9/16/22 4:07 AM, Liang He wrote:
quoted
In ping_unhash(), we should move sock_put(sk) after any possible
access point as the put function may free the object.
unhash handlers are called from sk_common_release which still has a
reference on the sock, so not really going to hit a UAF.
Thanks for this valuable lesson.
I do agree that it does not read correctly to 'put' a reference then
continue using the object. ie., the put should be moved to the end like
you have here. This is more of a tidiness exercise than a need to
backport to stable kernels.
OK, thanks.
quoted
Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind")
Signed-off-by: Liang He <redacted>
---
I have found other places containing similar code patterns.
net/ipv4/ping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)