[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANT5p=qEmVtgC5gD5G3D1o+7mxLMpQawnh0DSY+dLD-Dyrw5Uw@mail.gmail.com>
Date: Tue, 22 Mar 2022 11:37:08 +0530
From: Shyam Prasad N <nspmangalore@...il.com>
To: Xiaomeng Tong <xiam0nd.tong@...il.com>
Cc: Steven French <sfrench@...ba.org>, sprasad@...rosoft.com,
CIFS <linux-cifs@...r.kernel.org>,
samba-technical <samba-technical@...ts.samba.org>,
LKML <linux-kernel@...r.kernel.org>, jakobkoschel@...il.com
Subject: Re: [PATCH] cifs: fix incorrect use of list iterator after the loop
On Mon, Mar 21, 2022 at 3:50 PM Xiaomeng Tong <xiam0nd.tong@...il.com> wrote:
>
> The bug is here:
> if (!tcon) {
> resched = true;
> list_del_init(&ses->rlist);
> cifs_put_smb_ses(ses);
>
> Because the list_for_each_entry() never exits early (without any
> break/goto/return inside the loop), the iterator 'ses' after the
> loop will always be an pointer to a invalid struct containing the
> HEAD (&pserver->smb_ses_list). As a result, the uses of 'ses' above
> will lead to a invalid memory access.
>
> The original intention should have been to walk each entry 'ses' in
> '&tmp_ses_list', delete '&ses->rlist' and put 'ses'. So fix it with
> a list_for_each_entry_safe().
>
> Fixes: 3663c9045f51a ("cifs: check reconnects for channels of active tcons too")
> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@...il.com>
> ---
> fs/cifs/smb2pdu.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
> index 7e7909b1ae11..f82d6fcb5c64 100644
> --- a/fs/cifs/smb2pdu.c
> +++ b/fs/cifs/smb2pdu.c
> @@ -3858,8 +3858,10 @@ void smb2_reconnect_server(struct work_struct *work)
> tcon = kzalloc(sizeof(struct cifs_tcon), GFP_KERNEL);
> if (!tcon) {
> resched = true;
> - list_del_init(&ses->rlist);
> - cifs_put_smb_ses(ses);
> + list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) {
> + list_del_init(&ses->rlist);
> + cifs_put_smb_ses(ses);
> + }
> goto done;
> }
>
>
> base-commit: 14702b3b2438e2f2d07ae93b5d695c166e5c83d1
> --
> 2.17.1
>
Hi Xiaomeng,
Good catch.
Reviewed-by: Shyam Prasad N <sprasad@...rosoft.com>
Steve, This one needs to be marked for CC stable 5.17+
--
Regards,
Shyam
Powered by blists - more mailing lists