All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Kees Cook <keescook@chromium.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Leon Romanovsky <leon@kernel.org>,
	Bart Van Assche <Bart.VanAssche@wdc.com>,
	Doug Ledford <dledford@redhat.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] test_overflow: Add shift overflow tests
Date: Tue, 31 Jul 2018 20:13:53 -0600	[thread overview]
Message-ID: <20180801021353.GA31192@ziepe.ca> (raw)
In-Reply-To: <20180801000039.44314-3-keescook@chromium.org>

On Tue, Jul 31, 2018 at 05:00:38PM -0700, Kees Cook wrote:
> +	/* Overflow: high bit falls off. */
> +	/* 10010110 */
> +	err |= TEST_ONE_SHIFT(150, 1, u8, 0, true);
> +	/* 1000100010010110 */
> +	err |= TEST_ONE_SHIFT(34966, 1, u16, 0, true);
> +	/* 10000100000010001000100010010110 */
> +	err |= TEST_ONE_SHIFT(2215151766U, 1, u32, 0, true);
> +	err |= TEST_ONE_SHIFT(2215151766U, 1, unsigned int, 0, true);
> +	/* 1000001000010000010000000100000010000100000010001000100010010110 */
> +	err |= TEST_ONE_SHIFT(9372061470395238550ULL, 1, u64, 0, true);

This same idea should be repeated with signed outputs and check both
overflow past the end (<<2) and overflow into the signed bit (<<1)

        /* Overflow, high bit falls into the sign bit or off the end */
	/* 01001011 */
	err |= TEST_ONE_SHIFT(75, 1, s8, 0, true);
	err |= TEST_ONE_SHIFT(75, 2, s8, 0, true);

And also general type mismatch overflow:

	err |= TEST_ONE_SHIFT(0x100, 0, u8, 0, true);
	err |= TEST_ONE_SHIFT(0xFF, 0, s8, 0, true);

Thanks,
Jason

  reply	other threads:[~2018-08-01  2:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-01  0:00 [PATCH v2 0/3] overflow.h: Add arithmetic shift helper Kees Cook
2018-08-01  0:00 ` [PATCH v2 1/3] " Kees Cook
2018-08-01  1:59   ` Randy Dunlap
2018-08-01  2:15   ` Jason Gunthorpe
2018-08-01  4:22     ` Kees Cook
2018-08-01  7:57   ` Dan Carpenter
2018-08-01  8:07     ` Dan Carpenter
2018-08-01 15:38       ` Kees Cook
2018-08-01 15:48       ` Jason Gunthorpe
2018-08-01  0:00 ` [PATCH v2 2/3] test_overflow: Add shift overflow tests Kees Cook
2018-08-01  2:13   ` Jason Gunthorpe [this message]
2018-08-01  5:51     ` Kees Cook
2018-08-01  0:00 ` [PATCH v2 3/3] RDMA/mlx5: Fix shift overflow in mlx5_ib_create_wq Kees Cook

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=20180801021353.GA31192@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=Bart.VanAssche@wdc.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dledford@redhat.com \
    --cc=keescook@chromium.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /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.