* [PATCH] cifs: fix incorrect use of list iterator after the loop
@ 2022-03-20 13:50 Xiaomeng Tong
2022-03-22 6:07 ` Shyam Prasad N
0 siblings, 1 reply; 4+ messages in thread
From: Xiaomeng Tong @ 2022-03-20 13:50 UTC (permalink / raw)
To: sfrench
Cc: sprasad, linux-cifs, samba-technical, linux-kernel, jakobkoschel,
Xiaomeng Tong
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@gmail.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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: fix incorrect use of list iterator after the loop
2022-03-20 13:50 [PATCH] cifs: fix incorrect use of list iterator after the loop Xiaomeng Tong
@ 2022-03-22 6:07 ` Shyam Prasad N
2022-03-22 14:35 ` Steve French
2022-03-23 4:20 ` Steve French
0 siblings, 2 replies; 4+ messages in thread
From: Shyam Prasad N @ 2022-03-22 6:07 UTC (permalink / raw)
To: Xiaomeng Tong
Cc: Steven French, sprasad, CIFS, samba-technical, LKML, jakobkoschel
On Mon, Mar 21, 2022 at 3:50 PM Xiaomeng Tong <xiam0nd.tong@gmail.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@gmail.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@microsoft.com>
Steve, This one needs to be marked for CC stable 5.17+
--
Regards,
Shyam
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: fix incorrect use of list iterator after the loop
2022-03-22 6:07 ` Shyam Prasad N
@ 2022-03-22 14:35 ` Steve French
2022-03-23 4:20 ` Steve French
1 sibling, 0 replies; 4+ messages in thread
From: Steve French @ 2022-03-22 14:35 UTC (permalink / raw)
To: Shyam Prasad N
Cc: Xiaomeng Tong, CIFS, Shyam Prasad N, samba-technical, LKML,
Steven French, jakobkoschel
cc:stable too?
On Tue, Mar 22, 2022 at 1:09 AM Shyam Prasad N via samba-technical
<samba-technical@lists.samba.org> wrote:
>
> On Mon, Mar 21, 2022 at 3:50 PM Xiaomeng Tong <xiam0nd.tong@gmail.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@gmail.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@microsoft.com>
>
> Steve, This one needs to be marked for CC stable 5.17+
>
> --
> Regards,
> Shyam
>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: fix incorrect use of list iterator after the loop
2022-03-22 6:07 ` Shyam Prasad N
2022-03-22 14:35 ` Steve French
@ 2022-03-23 4:20 ` Steve French
1 sibling, 0 replies; 4+ messages in thread
From: Steve French @ 2022-03-23 4:20 UTC (permalink / raw)
To: Shyam Prasad N
Cc: Xiaomeng Tong, CIFS, Shyam Prasad N, samba-technical, LKML,
Steven French, jakobkoschel
tentatively merged into cifs-2.6.git for-next pending additional testing
Also added cc:stable 5.17
On Tue, Mar 22, 2022 at 1:09 AM Shyam Prasad N via samba-technical
<samba-technical@lists.samba.org> wrote:
>
> On Mon, Mar 21, 2022 at 3:50 PM Xiaomeng Tong <xiam0nd.tong@gmail.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@gmail.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@microsoft.com>
>
> Steve, This one needs to be marked for CC stable 5.17+
>
> --
> Regards,
> Shyam
>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-23 4:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-20 13:50 [PATCH] cifs: fix incorrect use of list iterator after the loop Xiaomeng Tong
2022-03-22 6:07 ` Shyam Prasad N
2022-03-22 14:35 ` Steve French
2022-03-23 4:20 ` Steve French
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.