Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ibmasm: fix heap over-read in ibmasm_send_i2o_message()

The ibmasm_send_i2o_message() function uses get_dot_command_size() to
compute the byte count for memcpy_toio(), but this value is derived from
user-controlled fields in the dot_command_header (command_size: u8,
data_size: u16) and is never validated against the actual allocation size.
A root user can write a small buffer with inflated header fields, causing
memcpy_toio() to read up to ~65 KB past the end of the allocation into
adjacent kernel heap, which is then forwarded to the service processor
over MMIO.

Silently clamping the copy size is not sufficient: if the header fields
claim a larger size than the buffer, the SP receives a dot command whose
own header is inconsistent with the I2O message length, which can cause
the SP to desynchronize. Reject such commands outright by returning
failure.

Validate command_size before calling get_mfa_inbound() to avoid leaking
an I2O message frame: reading INBOUND_QUEUE_PORT dequeues a hardware
frame from the controller's free pool, and returning without a
corresponding set_mfa_inbound() call would permanently exhaust it.

Additionally, clamp command_size to I2O_COMMAND_SIZE before the
memcpy_toio() so the MMIO write stays within the I2O message frame,
consistent with the clamping already performed by outgoing_message_size()
for the header field.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Tyllis Xu <LivelyCarpet87@gmail.com>
Link: https://patch.msgid.link/20260314165805.548293-1-LivelyCarpet87@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Tyllis Xu and committed by
Greg Kroah-Hartman
9aad7114 0eb09f73

+8 -4
+8 -4
drivers/misc/ibmasm/lowlevel.c
··· 19 19 int ibmasm_send_i2o_message(struct service_processor *sp) 20 20 { 21 21 u32 mfa; 22 - unsigned int command_size; 22 + size_t command_size; 23 23 struct i2o_message *message; 24 24 struct command *command = sp->current_command; 25 + 26 + command_size = get_dot_command_size(command->buffer); 27 + if (command_size > command->buffer_size) 28 + return 1; 29 + if (command_size > I2O_COMMAND_SIZE) 30 + command_size = I2O_COMMAND_SIZE; 25 31 26 32 mfa = get_mfa_inbound(sp->base_address); 27 33 if (!mfa) 28 34 return 1; 29 35 30 - command_size = get_dot_command_size(command->buffer); 31 - header.message_size = outgoing_message_size(command_size); 32 - 36 + header.message_size = outgoing_message_size((unsigned int)command_size); 33 37 message = get_i2o_message(sp->base_address, mfa); 34 38 35 39 memcpy_toio(&message->header, &header, sizeof(struct i2o_header));