All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@riscstar.com>
To: Dan Carpenter <dan.carpenter@linaro.org>,
	Jeff Layton <jlayton@kernel.org>
Cc: ceph-devel@vger.kernel.org
Subject: Re: [bug report] ceph: decode interval_sets for delegated inos
Date: Tue, 3 Dec 2024 11:06:50 -0600	[thread overview]
Message-ID: <d75b6bb5-f960-4e75-90f3-e7246a2cd295@riscstar.com> (raw)
In-Reply-To: <e660f348-5a0e-486d-8bae-e6c229f0e047@stanley.mountain>

On 12/3/24 2:19 AM, Dan Carpenter wrote:
> Hello Jeff Layton,
> 
> Commit d48464878708 ("ceph: decode interval_sets for delegated inos")
> from Nov 15, 2019 (linux-next), leads to the following Smatch static
> checker warning:
> 
> 	fs/ceph/mds_client.c:644 ceph_parse_deleg_inos()
> 	warn: potential user controlled sizeof overflow 'sets * 2 * 8' '0-u32max * 8'
> 
> fs/ceph/mds_client.c
>      637 static int ceph_parse_deleg_inos(void **p, void *end,
>      638                                  struct ceph_mds_session *s)
>      639 {
>      640         u32 sets;
>      641
>      642         ceph_decode_32_safe(p, end, sets, bad);
>                                              ^^^^
> set to user data here.
> 
>      643         if (sets)
> --> 644                 ceph_decode_skip_n(p, end, sets * 2 * sizeof(__le64), bad);
>                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^
> This is safe on 64bit but on 32bit systems it can integer overflow/wrap.

So the point of this is that "sets" is u32, and because that is
multiplied by 16 when passed to ceph_decode_skip_n(), the result
could exceed 32 bits?  I.e., would this address it?

	if (sets) {
	    size_t scale = 2 * sizeof(__le64);

	    if (sets < SIZE_MAX / scale)
		ceph_decode_skip_n(p, end, sets * scale, bad);
	    else
		goto bad;
	}

					-Alex


>      645         return 0;
>      646 bad:
>      647         return -EIO;
>      648 }
>      649
>      650 u64 ceph_get_deleg_ino(struct ceph_mds_session *s)
>      651 {
>      652         return 0;
>      653 }
>      654
> 
> regards,
> dan carpenter
> 


  parent reply	other threads:[~2024-12-03 17:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-03  8:19 [bug report] ceph: decode interval_sets for delegated inos Dan Carpenter
2024-12-03  8:25 ` Dan Carpenter
2024-12-03 14:07   ` Jeff Layton
2024-12-03 17:06 ` Alex Elder [this message]
2024-12-03 18:29   ` Dan Carpenter
2024-12-04 12:50     ` Alex Markuze
2024-12-04 13:12       ` Alex Markuze
2024-12-04 17:05         ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d75b6bb5-f960-4e75-90f3-e7246a2cd295@riscstar.com \
    --to=elder@riscstar.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=jlayton@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.