Le 18/08/2021 à 08:05, Kees Cook a écrit :
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 <b...@kernel.crashing.org>
Cc: Qinglang Miao <miaoqingl...@huawei.com>
Cc: "Gustavo A. R. Silva" <gustavo...@kernel.org>
Cc: Hulk Robot <hul...@huawei.com>
Cc: Wang Wensheng <wangwenshe...@huawei.com>
Cc: linuxppc-...@lists.ozlabs.org
Signed-off-by: Kees Cook <keesc...@chromium.org>
Reviewed-by: Michael Ellerman <m...@ellerman.id.au>
Link: https://lore.kernel.org/lkml/87czqsnmw9....@mpe.ellerman.id.au
---
  drivers/macintosh/smu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index 94fb63a7b357..59ce431da7ef 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -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, 3);

subaddr[] is a table, should the & be avoided ?
And while at it, why not use sizeof(subaddr) instead of 3 ?


                break;
        case SMU_I2C_TRANSFER_COMBINED:
                cmd->info.devaddr &= 0xfe;

Reply via email to