[Cluster-devel] 回复: [PATCH v1] fs:dlm:Fix NULL pointer dereference bug in accept_from_sock()

王明-软件底层技术部 machel at vivo.com
Wed Jul 5 01:16:49 UTC 2023


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 <aahringo at redhat.com> 
发送时间: 2023年7月5日 0:22
收件人: 王明-软件底层技术部 <machel at vivo.com>
抄送: Christine Caulfield <ccaulfie at redhat.com>; David Teigland <teigland at redhat.com>; cluster-devel at redhat.com; linux-kernel at vger.kernel.org; opensource.kernel <opensource.kernel at vivo.com>
主题: 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,

On Tue, Jul 4, 2023 at 6:56 AM Wang Ming <machel at vivo.com> 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?

> Signed-off-by: Wang Ming <machel at vivo.com>
> ---
>  fs/dlm/lowcomms.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 
> 9f14ea9f6..ea18b9478 100644
> --- a/fs/dlm/lowcomms.c
> +++ b/fs/dlm/lowcomms.c
> @@ -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?

>                 /* 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.

> +               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



More information about the Cluster-devel mailing list