linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* re: libceph: follow redirect replies from osds
@ 2020-02-28 12:46 Colin Ian King
  2020-02-28 14:01 ` Jeff Layton
  0 siblings, 1 reply; 3+ messages in thread
From: Colin Ian King @ 2020-02-28 12:46 UTC (permalink / raw)
  To: Ilya Dryomov, Jeff Layton, Sage Weil, ceph-devel; +Cc: linux-kernel

Hi,

Static analysis with Coverity has detected a potential issue in the
following commit in function ceph_redirect_decode():

commit 205ee1187a671c3b067d7f1e974903b44036f270
Author: Ilya Dryomov <ilya.dryomov@inktank.com>
Date:   Mon Jan 27 17:40:20 2014 +0200

    libceph: follow redirect replies from osds

The issue is as follows:


3486        len = ceph_decode_32(p);

Unused value (UNUSED_VALUE)
assigned_pointer: Assigning value from len to *p here, but that stored
value is overwritten before it can be used.

3487        *p += len; /* skip osd_instructions */
3488
3489        /* skip the rest */

value_overwrite: Overwriting previous write to *p with value from
struct_end.

3490        *p = struct_end;

The *p assignment in line 3487 is effectively being overwritten by the
*p assignment in 3490.  Maybe the following is correct:

        len = ceph_decode_32(p);
-       p += len; /* skip osd_instructions */
+       struct_end = *p + len;  /* skip osd_instructions */

        /* skip the rest */
        *p = struct_end;

I'm not familiar with the ceph structure here, so I'm not sure what the
correct fix would be.

Colin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libceph: follow redirect replies from osds
  2020-02-28 12:46 libceph: follow redirect replies from osds Colin Ian King
@ 2020-02-28 14:01 ` Jeff Layton
  2020-02-28 14:13   ` Ilya Dryomov
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Layton @ 2020-02-28 14:01 UTC (permalink / raw)
  To: Colin Ian King, Ilya Dryomov, Sage Weil, ceph-devel; +Cc: linux-kernel

On Fri, 2020-02-28 at 12:46 +0000, Colin Ian King wrote:
> Hi,
> 
> Static analysis with Coverity has detected a potential issue in the
> following commit in function ceph_redirect_decode():
> 
> commit 205ee1187a671c3b067d7f1e974903b44036f270
> Author: Ilya Dryomov <ilya.dryomov@inktank.com>
> Date:   Mon Jan 27 17:40:20 2014 +0200
> 
>     libceph: follow redirect replies from osds
> 
> The issue is as follows:
> 
> 
> 3486        len = ceph_decode_32(p);
> 
> Unused value (UNUSED_VALUE)
> assigned_pointer: Assigning value from len to *p here, but that stored
> value is overwritten before it can be used.
> 
> 3487        *p += len; /* skip osd_instructions */
> 3488
> 3489        /* skip the rest */
> 
> value_overwrite: Overwriting previous write to *p with value from
> struct_end.
> 
> 3490        *p = struct_end;
> 
> The *p assignment in line 3487 is effectively being overwritten by the
> *p assignment in 3490.  Maybe the following is correct:
> 
>         len = ceph_decode_32(p);
> -       p += len; /* skip osd_instructions */
> +       struct_end = *p + len;  /* skip osd_instructions */
> 
>         /* skip the rest */
>         *p = struct_end;
> 
> I'm not familiar with the ceph structure here, so I'm not sure what the
> correct fix would be.
> 

Probably something like this? (untested, of course)

----------------------

[PATCH] libceph: fix up Coverity warning in ceph_redirect_decode

We're going to skip to the end of the msg after checking the
object_name anyway, so there is no need to separately decode
the osd instructions that follow it.

Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 net/ceph/osd_client.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 8ff2856e2d52..51810db4130a 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -3483,9 +3483,6 @@ static int ceph_redirect_decode(void **p, void
*end,
 		goto e_inval;
 	}
 
-	len = ceph_decode_32(p);
-	*p += len; /* skip osd_instructions */
-
 	/* skip the rest */
 	*p = struct_end;
 out:
-- 
2.24.1





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: libceph: follow redirect replies from osds
  2020-02-28 14:01 ` Jeff Layton
@ 2020-02-28 14:13   ` Ilya Dryomov
  0 siblings, 0 replies; 3+ messages in thread
From: Ilya Dryomov @ 2020-02-28 14:13 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Colin Ian King, Sage Weil, Ceph Development, linux-kernel

On Fri, Feb 28, 2020 at 3:01 PM Jeff Layton <jlayton@kernel.org> wrote:
>
> On Fri, 2020-02-28 at 12:46 +0000, Colin Ian King wrote:
> > Hi,
> >
> > Static analysis with Coverity has detected a potential issue in the
> > following commit in function ceph_redirect_decode():
> >
> > commit 205ee1187a671c3b067d7f1e974903b44036f270
> > Author: Ilya Dryomov <ilya.dryomov@inktank.com>
> > Date:   Mon Jan 27 17:40:20 2014 +0200
> >
> >     libceph: follow redirect replies from osds
> >
> > The issue is as follows:
> >
> >
> > 3486        len = ceph_decode_32(p);
> >
> > Unused value (UNUSED_VALUE)
> > assigned_pointer: Assigning value from len to *p here, but that stored
> > value is overwritten before it can be used.
> >
> > 3487        *p += len; /* skip osd_instructions */
> > 3488
> > 3489        /* skip the rest */
> >
> > value_overwrite: Overwriting previous write to *p with value from
> > struct_end.
> >
> > 3490        *p = struct_end;
> >
> > The *p assignment in line 3487 is effectively being overwritten by the
> > *p assignment in 3490.  Maybe the following is correct:
> >
> >         len = ceph_decode_32(p);
> > -       p += len; /* skip osd_instructions */
> > +       struct_end = *p + len;  /* skip osd_instructions */
> >
> >         /* skip the rest */
> >         *p = struct_end;
> >
> > I'm not familiar with the ceph structure here, so I'm not sure what the
> > correct fix would be.
> >
>
> Probably something like this? (untested, of course)
>
> ----------------------
>
> [PATCH] libceph: fix up Coverity warning in ceph_redirect_decode
>
> We're going to skip to the end of the msg after checking the
> object_name anyway, so there is no need to separately decode
> the osd instructions that follow it.
>
> Reported-by: Colin Ian King <colin.king@canonical.com>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
>  net/ceph/osd_client.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
> index 8ff2856e2d52..51810db4130a 100644
> --- a/net/ceph/osd_client.c
> +++ b/net/ceph/osd_client.c
> @@ -3483,9 +3483,6 @@ static int ceph_redirect_decode(void **p, void
> *end,
>                 goto e_inval;
>         }
>
> -       len = ceph_decode_32(p);
> -       *p += len; /* skip osd_instructions */
> -
>         /* skip the rest */
>         *p = struct_end;
>  out:

Yeah, I have had the same patch in a local branch here since last year:

https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg2092861.html

I'll make sure to push it out this time ;)

Thanks,

                Ilya

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-28 14:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-28 12:46 libceph: follow redirect replies from osds Colin Ian King
2020-02-28 14:01 ` Jeff Layton
2020-02-28 14:13   ` Ilya Dryomov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).