]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
powerpc: Split memset() to avoid multi-field overflow
authorKees Cook <keescook@chromium.org>
Mon, 21 Jun 2021 19:01:01 +0000 (12:01 -0700)
committerKees Cook <keescook@chromium.org>
Sat, 25 Sep 2021 15:20:47 +0000 (08:20 -0700)
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.

Instead of writing across a field boundary with memset(), move the call
to just the array, and an explicit zeroing of the prior field.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Qinglang Miao <miaoqinglang@huawei.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Hulk Robot <hulkci@huawei.com>
Cc: Wang Wensheng <wangwensheng4@huawei.com>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/lkml/87czqsnmw9.fsf@mpe.ellerman.id.au
drivers/macintosh/smu.c

index fe63d5ee201b866c0e0681b9605e60ba4aaf2720..d33913d523c1d5fcaf9fab4bbc09e81c014e1e74 100644 (file)
@@ -848,7 +848,8 @@ int smu_queue_i2c(struct smu_i2c_cmd *cmd)
        cmd->read = cmd->info.devaddr & 0x01;
        switch(cmd->info.type) {
        case SMU_I2C_TRANSFER_SIMPLE:
-               memset(&cmd->info.sublen, 0, 4);
+               cmd->info.sublen = 0;
+               memset(cmd->info.subaddr, 0, sizeof(cmd->info.subaddr));
                break;
        case SMU_I2C_TRANSFER_COMBINED:
                cmd->info.devaddr &= 0xfe;