From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 863D4173 for ; Wed, 18 Aug 2021 22:30:03 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id m24-20020a17090a7f98b0290178b1a81700so3398712pjl.4 for ; Wed, 18 Aug 2021 15:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=DUTuMfsQqxqX+3pR2oz9dVJNWsHg80kq142ck8zdj0s=; b=HXqi8rpNQlqRCRobulkOlcaA4+c6J/4aW1kHG07w5z+LW3VAsPY7L3ovHbYLAvr6BW z8PYA40q5a4/E1aSSd1f0X7nRnd2FNDMsOqvNHCn+M7iSwPw+3HB842oCYFV1odUjD4+ aowm4n1LLC28ISLDG0efepefjXmirvRMkeWhE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=DUTuMfsQqxqX+3pR2oz9dVJNWsHg80kq142ck8zdj0s=; b=D5bGJ6bg83ac+J0eHBZNVi54Y5EOErNdOnAfbNKG8AV0lybT1wroPm4+kP8anaZl1X Oytrc3bdJ0iKQz9k/68hiDVuE6L5Ab5lE8WdVGkgW3QWtuWIxmWJ+kwKymH+jNd9iTNK lHviyywk8UP1/nctEDnNCSrOlbd2kblZ25x0S6jiPIN/fo1DZ+SbosJCJowrotEL6gp/ YlapWNBaYbW4CB1YUb6dSDrHbwULOXf7GHKqMRRAGJKsIEV8xj7LMoEDrDf6sh6GyULm GKlB7+Rauw7YwCzPyW/TqCCcz5f0dCHO1qH5D3UQ63aGb6tTWml0dBb0HxrbDTxtdGzd egsQ== X-Gm-Message-State: AOAM531U40dJyuzpuxWIsFDYousJTujSuUFvxUYUl3OoYPL8soSjW+MV msTHBTiGpOQc10NFDO68J+1Eeg== X-Google-Smtp-Source: ABdhPJwejqek+pQNgEJHoUL+LD8id8sswOa0BezZLWGyCwRRYJ3BmiAhJE1bgJAMyKte9lbr8NDHRw== X-Received: by 2002:a17:90a:a581:: with SMTP id b1mr1663300pjq.153.1629325803017; Wed, 18 Aug 2021 15:30:03 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n185sm862325pfn.171.2021.08.18.15.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 15:30:02 -0700 (PDT) Date: Wed, 18 Aug 2021 15:30:01 -0700 From: Kees Cook To: Christophe Leroy Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , Greg Kroah-Hartman , Wang Wensheng , linux-staging@lists.linux.dev, linux-wireless@vger.kernel.org, "Gustavo A. R. Silva" , Qinglang Miao , linux-block@vger.kernel.org, Hulk Robot , clang-built-linux@googlegroups.com, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 61/63] powerpc: Split memset() to avoid multi-field overflow Message-ID: <202108181528.9CDB56FEC@keescook> References: <20210818060533.3569517-1-keescook@chromium.org> <20210818060533.3569517-62-keescook@chromium.org> <7630b0bc-4389-6283-d8b9-c532df916d60@csgroup.eu> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7630b0bc-4389-6283-d8b9-c532df916d60@csgroup.eu> On Wed, Aug 18, 2021 at 08:42:18AM +0200, Christophe Leroy wrote: > > > 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 > > Cc: Qinglang Miao > > Cc: "Gustavo A. R. Silva" > > Cc: Hulk Robot > > Cc: Wang Wensheng > > Cc: linuxppc-dev@lists.ozlabs.org > > Signed-off-by: Kees Cook > > Reviewed-by: Michael Ellerman > > Link: https://lore.kernel.org/lkml/87czqsnmw9.fsf@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 ? It results in the same thing, but it's better form to not have the &; I will fix this. > And while at it, why not use sizeof(subaddr) instead of 3 ? Agreed. :) Thanks! -- Kees Cook From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61412C4338F for ; Wed, 18 Aug 2021 22:30:53 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E0056101A for ; Wed, 18 Aug 2021 22:30:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5E0056101A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GqjKQ6SFKz3cKW for ; Thu, 19 Aug 2021 08:30:50 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HXqi8rpN; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=chromium.org (client-ip=2607:f8b0:4864:20::62e; helo=mail-pl1-x62e.google.com; envelope-from=keescook@chromium.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HXqi8rpN; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GqjJd4tQqz2yXt for ; Thu, 19 Aug 2021 08:30:07 +1000 (AEST) Received: by mail-pl1-x62e.google.com with SMTP id n12so2769990plf.4 for ; Wed, 18 Aug 2021 15:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=DUTuMfsQqxqX+3pR2oz9dVJNWsHg80kq142ck8zdj0s=; b=HXqi8rpNQlqRCRobulkOlcaA4+c6J/4aW1kHG07w5z+LW3VAsPY7L3ovHbYLAvr6BW z8PYA40q5a4/E1aSSd1f0X7nRnd2FNDMsOqvNHCn+M7iSwPw+3HB842oCYFV1odUjD4+ aowm4n1LLC28ISLDG0efepefjXmirvRMkeWhE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=DUTuMfsQqxqX+3pR2oz9dVJNWsHg80kq142ck8zdj0s=; b=PeJ7Va0EvPX0GH3z4cDELGGx6Fc3f0tkbzOPbsuCsFbYO3ahzYIFVFGfbjOBVvGHEt G7RdmDh47kvm3qJ6EN6UMLqSdcGYz+TKtNW0agUbY1jFKXzGK4M91VS5y8gnAejsC4+r 7JSw4OmyhmbCgixnEgWivsDTrHZE0Ypg7a85Oigz2QHO/XNJvLoUnOEKKLFE/w06rBK4 fyqQA7eCUzXlboUMe6OEVuqknQGINJjMGuorKhD4Q8W1whyhnYa/qLsXFkPpz3mFMCoq tJN89Ngx/GcCyG0+MjVV9vycNcJ62uTsVlt1MC87QcM5FvTt+3RQ5T7YwG9xCLCqAJaD nyCg== X-Gm-Message-State: AOAM532incomhsePwQpCLTRZ0ocBXSVxAJTNF9BeMj/Mz7Yn2y27sRCu r9jXdu1t4uI56Qtl6NZ3KLF7AQ== X-Google-Smtp-Source: ABdhPJwejqek+pQNgEJHoUL+LD8id8sswOa0BezZLWGyCwRRYJ3BmiAhJE1bgJAMyKte9lbr8NDHRw== X-Received: by 2002:a17:90a:a581:: with SMTP id b1mr1663300pjq.153.1629325803017; Wed, 18 Aug 2021 15:30:03 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n185sm862325pfn.171.2021.08.18.15.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 15:30:02 -0700 (PDT) Date: Wed, 18 Aug 2021 15:30:01 -0700 From: Kees Cook To: Christophe Leroy Subject: Re: [PATCH v2 61/63] powerpc: Split memset() to avoid multi-field overflow Message-ID: <202108181528.9CDB56FEC@keescook> References: <20210818060533.3569517-1-keescook@chromium.org> <20210818060533.3569517-62-keescook@chromium.org> <7630b0bc-4389-6283-d8b9-c532df916d60@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7630b0bc-4389-6283-d8b9-c532df916d60@csgroup.eu> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rasmus Villemoes , clang-built-linux@googlegroups.com, Greg Kroah-Hartman , Wang Wensheng , linux-staging@lists.linux.dev, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Qinglang Miao , "Gustavo A. R. Silva" , linux-block@vger.kernel.org, Hulk Robot , dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Wed, Aug 18, 2021 at 08:42:18AM +0200, Christophe Leroy wrote: > > > 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 > > Cc: Qinglang Miao > > Cc: "Gustavo A. R. Silva" > > Cc: Hulk Robot > > Cc: Wang Wensheng > > Cc: linuxppc-dev@lists.ozlabs.org > > Signed-off-by: Kees Cook > > Reviewed-by: Michael Ellerman > > Link: https://lore.kernel.org/lkml/87czqsnmw9.fsf@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 ? It results in the same thing, but it's better form to not have the &; I will fix this. > And while at it, why not use sizeof(subaddr) instead of 3 ? Agreed. :) Thanks! -- Kees Cook