From: Rouven Czerwinski <r.czerwinski@pengutronix.de>
To: Ahmad Fatoum <ahmad@a3f.at>, barebox@lists.infradead.org
Subject: Re: [PATCH v1 3/4] common: ubsan: ignore shifting one into sign bit
Date: Sat, 21 Sep 2019 09:47:47 +0200 [thread overview]
Message-ID: <d2162c1bbd3785e1891e8a813e0436d045a3cb17.camel@pengutronix.de> (raw)
In-Reply-To: <20190920075813.22471-3-ahmad@a3f.at>
Hi Ahmad,
On Fri, 2019-09-20 at 09:58 +0200, Ahmad Fatoum wrote:
> The __ubsan_handle_shift_out_of_bounds handler would be called for
> code
> shifting a one into the sign bit like (1 << 31), which is all too
> common
> in barebox. It's technically UB, but it's so prevalent that it's
> highly
> unlikely to be treated by a compiler as anything else than the
> standard-compliant (1U << 31).
>
> Check for this case here and ignore it selectively.
Shouldn't we rather fix the the (1 << 31) to be (1U <<31)?
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
> lib/ubsan.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/lib/ubsan.c b/lib/ubsan.c
> index 89ca6e580bce..41a5731dda66 100644
> --- a/lib/ubsan.c
> +++ b/lib/ubsan.c
> @@ -382,6 +382,26 @@ void __ubsan_handle_shift_out_of_bounds(struct
> shift_out_of_bounds_data *data,
> if (suppress_report(&data->location))
> return;
>
> + /* This handler would be called for code shifting a one into
> the
> + * sign bit like (1 << 31), which is all too common in barebox.
> + * It's technically UB, but it's so prevalent that it's highly
> + * unlikely to be treated by a compiler as anything else than
> the
> + * standard-compliant (1U << 31). Thus check for this case here
> + * and ignore it selectively
> + */
> + if (type_is_signed(lhs_type)) {
> + s_max lhs_int, rhs_int;
> +
> + lhs_int = get_signed_val(lhs_type, lhs);
> + rhs_int = get_signed_val(rhs_type, rhs);
> +
> + if (fls(lhs_int) + rhs_int == type_bit_width(lhs_type))
> {
> + pr_debug("signed left shift of %lld by %lld
> ignored.\n",
> + (s64)lhs_int, (s64)rhs_int);
> + return;
> + }
> + }
> +
> ubsan_prologue(&data->location, &flags);
>
> val_to_string(rhs_str, sizeof(rhs_str), rhs_type, rhs);
- rcz
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-09-21 7:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-20 7:58 [PATCH v1 1/4] console: disallow opening for writing when no write method defined Ahmad Fatoum
2019-09-20 7:58 ` [PATCH v1 2/4] input: set console input name as input Ahmad Fatoum
2019-09-20 7:58 ` [PATCH v1 3/4] common: ubsan: ignore shifting one into sign bit Ahmad Fatoum
2019-09-21 7:47 ` Rouven Czerwinski [this message]
2019-09-21 10:59 ` Ahmad Fatoum
2019-09-20 7:58 ` [PATCH v1 4/4] USB: gadget: ACM: don't announce V.25ter support Ahmad Fatoum
2019-09-20 8:51 ` Ahmad Fatoum
2019-09-21 11:00 ` Ahmad Fatoum
2019-09-23 6:59 ` [PATCH v1 1/4] console: disallow opening for writing when no write method defined Sascha Hauer
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=d2162c1bbd3785e1891e8a813e0436d045a3cb17.camel@pengutronix.de \
--to=r.czerwinski@pengutronix.de \
--cc=ahmad@a3f.at \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox