fs:dlm:Fix NULL pointer dereference bug in accept_from_sock()
PATCH 1/1 fs:dlm:Fix NULL pointer dereference bug in accept_from_sock()
newcon -> sock is NULL but dereferenced. First check newcon. Whether sock is a null pointer. If so, the subsequent operations are skipped. If it is not empty, perform subsequent operations.
--- fs/dlm/lowcomms.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/dlm/lowcomms.c +6 -3
@@ -1081,9 +1081,12 @@ static int accept_from_sock(void)add_sock (newsock, newcon);/* check if we receved something while adding */ -lock_sock (newcon->sock->sk); -lowcomms_queue_rwork (newcon); -release_sock (newcon->sock->sk); +if (newcon->sock) { +lock_sock (newcon->sock->sk); +lowcomms_queue_rwork (newcon); +release_sock (newcon->sock->sk); + } + }up_write (&newcon->sock_lock);srcu_read_unlock (&connections_srcu, idx);
Signature · 1 line
2.25.1
Alexander Aring
maintainerHi,
Quoted 6 lines · On Tue, Jul 4, 2023 at 6:56?AM Wang Ming <[email protected]> wrote:
newcon -> sock is NULL but dereferenced. First check newcon. Whether sock is a null pointer. If so, the subsequent operations are skipped. If it is not empty, perform subsequent operations.
did you experience some null pointer dereference? If so, on which kernel was it?
fs/dlm/lowcomms.c static int accept_from_sock(void) · line 1082
Quoted 12 lines
Signed-off-by Wang Ming <[email protected]>--- fs/dlm/lowcomms.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fs/dlm/lowcomms.c +0
-0@@ -1081,9 +1081,12 @@ static int accept_from_sock(void)add_sock (newsock, newcon);
Here in add_sock() we assign newcon->sock = newsock. It cannot fail and newsock cannot be null, so holding the newcon->sock_lock write protected _should_ be safe that others don't manipulate newcon->sock. It should, that's why I am asking if you experienced some issue here?
fs/dlm/lowcomms.c static int accept_from_sock(void) · line 1086
Quoted 4 lines
fs/dlm/lowcomms.c +0
-3/* check if we receved something while adding */ -lock_sock (newcon->sock->sk); -lowcomms_queue_rwork (newcon); -release_sock (newcon->sock->sk);
see above, newcon->sock should always be set at this point.
fs/dlm/lowcomms.c static int accept_from_sock(void) · line 1092
Quoted 9 lines
fs/dlm/lowcomms.c +6
-0+if (newcon->sock) { +lock_sock (newcon->sock->sk); +lowcomms_queue_rwork (newcon); +release_sock (newcon->sock->sk); + } + }up_write (&newcon->sock_lock);srcu_read_unlock (&connections_srcu, idx);
- Alex
Thank you. I see. I hadn't noticed what the add_sock() function did before, but now I understand that newcon->sock will not be a null pointer.
-----????-----
???: Alexander Aring <[email protected]>
????: 2023?7?5? 0:22
???: ??-??????? <[email protected]>
??: Christine Caulfield <[email protected]>; David Teigland <[email protected]>; cluster-devel at redhat.com; linux-kernel at vger.kernel.org; opensource.kernel <[email protected]> ??: Re: [Cluster-devel] [PATCH v1] fs:dlm:Fix NULL pointer dereference bug in accept_from_sock()
[????????? aahringo at redhat.com ????????? https://aka.ms/LearnAboutSenderIdentification?????????????]
Hi,
Quoted 6 lines · On Tue, Jul 4, 2023 at 6:56?AM Wang Ming <[email protected]> wrote:
newcon -> sock is NULL but dereferenced. First check newcon. Whether sock is a null pointer. If so, the subsequent operations are skipped. If it is not empty, perform subsequent operations.
did you experience some null pointer dereference? If so, on which kernel was it?
fs/dlm/lowcomms.c static int accept_from_sock(void) · line 1082
Quoted 12 lines
Signed-off-by Wang Ming <[email protected]>--- fs/dlm/lowcomms.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fs/dlm/lowcomms.c index renamed from fs/dlm/lowcomms.c +0
-0
9f14ea9f6..ea18b9478100644fs/dlm/lowcomms.c +0
-0@@ -1081,9 +1081,12 @@ static int accept_from_sock(void)add_sock (newsock, newcon);
Here in add_sock() we assign newcon->sock = newsock. It cannot fail and newsock cannot be null, so holding the newcon->sock_lock write protected _should_ be safe that others don't manipulate newcon->sock. It should, that's why I am asking if you experienced some issue here?
fs/dlm/lowcomms.c static int accept_from_sock(void) · line 1086
Quoted 4 lines
fs/dlm/lowcomms.c +0
-3/* check if we receved something while adding */ -lock_sock (newcon->sock->sk); -lowcomms_queue_rwork (newcon); -release_sock (newcon->sock->sk);
see above, newcon->sock should always be set at this point.
fs/dlm/lowcomms.c static int accept_from_sock(void) · line 1092
Quoted 9 lines
fs/dlm/lowcomms.c +6
-0+if (newcon->sock) { +lock_sock (newcon->sock->sk); +lowcomms_queue_rwork (newcon); +release_sock (newcon->sock->sk); + } + }up_write (&newcon->sock_lock);srcu_read_unlock (&connections_srcu, idx);
- Alex