Skip to content

Commit 0627cef

Browse files
Dan Carpentercminyard
authored andcommitted
ipmi: ssif_bmc: prevent integer overflow on 32bit systems
There are actually two bugs here. First, we need to ensure that count is at least sizeof(u32) or msg.len will be uninitialized data. The "msg.len" variable is a u32 that comes from the user. On 32bit systems the "sizeof_field(struct ipmi_ssif_msg, len) + msg.len" addition can overflow if "msg.len" is greater than U32_MAX - 4. Valid lengths for "msg.len" are 1-254. Add a check for that to prevent the integer overflow. Fixes: dd2bc5c ("ipmi: ssif_bmc: Add SSIF BMC driver") Signed-off-by: Dan Carpenter <[email protected]> Message-Id: <[email protected]> Signed-off-by: Corey Minyard <[email protected]>
1 parent 0cac73e commit 0627cef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/char/ipmi/ssif_bmc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,15 @@ static ssize_t ssif_bmc_write(struct file *file, const char __user *buf, size_t
177177
unsigned long flags;
178178
ssize_t ret;
179179

180-
if (count > sizeof(struct ipmi_ssif_msg))
180+
if (count < sizeof(msg.len) ||
181+
count > sizeof(struct ipmi_ssif_msg))
181182
return -EINVAL;
182183

183184
if (copy_from_user(&msg, buf, count))
184185
return -EFAULT;
185186

186-
if (!msg.len || count < sizeof_field(struct ipmi_ssif_msg, len) + msg.len)
187+
if (!msg.len || msg.len > IPMI_SSIF_PAYLOAD_MAX ||
188+
count < sizeof_field(struct ipmi_ssif_msg, len) + msg.len)
187189
return -EINVAL;
188190

189191
spin_lock_irqsave(&ssif_bmc->lock, flags);

0 commit comments

Comments
 (0)