From: Colin King <colin.king@canonical.com>
To: Jaroslav Kysela <perex@perex.cz>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] PNP: fix unintended sign extension on left shifts
Date: Mon, 14 Oct 2019 14:16:08 +0100 [thread overview]
Message-ID: <20191014131608.31335-1-colin.king@canonical.com> (raw)
From: Colin Ian King <colin.king@canonical.com>
Shifting a u8 left will cause the value to be promoted to an integer. If
the top bit of the u8 is set then the following conversion to a 64 bit
resource_size_t will sign extend the value causing the upper 32 bits
to be set in the result.
Fix this by casting the u8 value to a resource_size_t before the shift.
Original commit is pre-git history.
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/pnp/isapnp/core.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index 179b737280e1..c947b1673041 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -511,10 +511,14 @@ static void __init isapnp_parse_mem32_resource(struct pnp_dev *dev,
unsigned char flags;
isapnp_peek(tmp, size);
- min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
- max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
- align = (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9];
- len = (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
+ min = ((resource_size_t)tmp[4] << 24) | (tmp[3] << 16) |
+ (tmp[2] << 8) | tmp[1];
+ max = ((resource_size_t)tmp[8] << 24) | (tmp[7] << 16) |
+ (tmp[6] << 8) | tmp[5];
+ align = ((resource_size_t)tmp[12] << 24) | (tmp[11] << 16) |
+ (tmp[10] << 8) | tmp[9];
+ len = ((resource_size_t)tmp[16] << 24) | (tmp[15] << 16) |
+ (tmp[14] << 8) | tmp[13];
flags = tmp[0];
pnp_register_mem_resource(dev, option_flags,
min, max, align, len, flags);
@@ -532,8 +536,10 @@ static void __init isapnp_parse_fixed_mem32_resource(struct pnp_dev *dev,
unsigned char flags;
isapnp_peek(tmp, size);
- base = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
- len = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
+ base = ((resource_size_t)tmp[4] << 24) | (tmp[3] << 16) |
+ (tmp[2] << 8) | tmp[1];
+ len = ((resource_size_t)tmp[8] << 24) | (tmp[7] << 16) |
+ (tmp[6] << 8) | tmp[5];
flags = tmp[0];
pnp_register_mem_resource(dev, option_flags, base, base, 0, len, flags);
}
--
2.20.1
next reply other threads:[~2019-10-14 13:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-14 13:16 Colin King [this message]
2019-10-15 16:29 ` Rafael J. Wysocki
2019-10-16 7:20 ` walter harms
2019-10-18 10:15 ` Rafael J. Wysocki
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=20191014131608.31335-1-colin.king@canonical.com \
--to=colin.king@canonical.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=rafael.j.wysocki@intel.com \
/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
all inboxes | Powered by JetHome®