Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp251288rwb; Mon, 26 Sep 2022 18:17:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Z9yM1lQ7kPusRREyFpSLJ6SN3I32XtxMBXm4ENkSF8kXmBvHLSltfG8cF7e77hCMJMDFa X-Received: by 2002:a17:90b:3b43:b0:202:d053:d305 with SMTP id ot3-20020a17090b3b4300b00202d053d305mr1638035pjb.229.1664241437950; Mon, 26 Sep 2022 18:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664241437; cv=none; d=google.com; s=arc-20160816; b=LqnvKC5Fm3KbZbbSQ7ZuUC/KBISBnvPdGdAB57bItPOT8EikAvOcgdxhQYicaxFhT5 PGxGP1C2JR+evepFYko2+ZQzARqZSYDZzcXculgQqfk12yOf9fiIVPBlHWy/CU0zdM+5 Dbc9W6wGDaQNEyyOi6hSdCJ9dh9dc8yoNlblnum7PL69s4LooOlEvWkT1mW/0ZPASIji kCucrZX16TnhCFzo+lCoEVqiT8ROg/4GCfLqbGNLJyf4KxNEZANOrG5k6CnP7t/iqDjp Q4A8Z4lQdYt3T2T+dmTX91rtNXa9V585UY5RPT8/LxBKScS/AX6aoNu/heiu0aX3c0gH NWmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QbjxUsr8xwzFpCbVDwHMoOW/GoW/dESSMoVWzDqLx8M=; b=FugbHKnFXGu85wVMGlFinYQWoiC6I7yfq1xFkr1ohRqx/dWlwQHfeoJcvKXLJl59ht EGyG2U/LAFX3E+MzvLYmRIVPFVdSbnX6my0g+YrwCgeO8OV7ybQn9Z3JAZTk0kzNx/oC Ug0c6cuAJHdGgRhn/fOGWGAm/xq48qhmUjK2QVNI4K/Xi5s+CYeJQDVpVP/0oLlbJ2jR 8K2B6G8M4MEon00mZAQPRyH/gfbICqHw9jAfY+wMg997gA6V9FIL8fVihKeSnlul7JfT Q3XucOqdHqs3FoXNgz25H6454snxZgYa8cADyutrlsrXdDg6KmxPPnYkVASMQrfOky/G olcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ikeX8zDY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a170903029100b00179c4bebb6bsi163361plr.409.2022.09.26.18.17.06; Mon, 26 Sep 2022 18:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ikeX8zDY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229488AbiI0BM7 (ORCPT + 99 others); Mon, 26 Sep 2022 21:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbiI0BM5 (ORCPT ); Mon, 26 Sep 2022 21:12:57 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06F849B872; Mon, 26 Sep 2022 18:12:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 30E0ACE13E7; Tue, 27 Sep 2022 01:12:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED2CBC433C1; Tue, 27 Sep 2022 01:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664241172; bh=LkKSel0RdldqvXm8rwrJJuPghKrZg2g8e51qKRvCa9k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ikeX8zDYwKANctxavY3Xo8m9v4ulsS7NLH6QPpipbfZnVOBKLejB7PZtHoNvc2GU9 3Fg79+ZbcF6jJCl2fIbNXxvnMXemfCUWaFzZmCqqmuHwRynROEbBMBdAnK+/N7pJ9b Yc7EhieMbTSzsbAspIizPiXXTbifuyzDK+kCmsWzA0S84at0ocXTM6VHHNRpaIJzRA YLj6roYKVcvTTde9IEF+WmeBR7qmcealnWrwGzpQ75gi0/b3ADzcZW/mwlxhpMBzjh ItIL6Sx4f86ssi9SO+nQ4a/ghKbHpt0Y0X596DXbfSE/UTXXlVVosYVPHkoZ25m0kC Gd1mH+kraml8A== Date: Mon, 26 Sep 2022 20:12:46 -0500 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Maximilian Luz , Hans de Goede , Mark Gross , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] platform/surface: Split memcpy() of struct ssam_event flexible array Message-ID: References: <20220927004011.1942739-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220927004011.1942739-1-keescook@chromium.org> X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 26, 2022 at 05:40:11PM -0700, Kees Cook wrote: > To work around a misbehavior of the compiler's ability to see into > composite flexible array structs (as detailed in the coming memcpy() > hardening series[1]), split the memcpy() of the header and the payload > so no false positive run-time overflow warning will be generated. > > [1] https://lore.kernel.org/linux-hardening/20220901065914.1417829-2-keescook@chromium.org > > Cc: Maximilian Luz > Cc: Hans de Goede > Cc: Mark Gross > Cc: platform-driver-x86@vger.kernel.org > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks! -- Gustavo > --- > drivers/platform/surface/surface_acpi_notify.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/platform/surface/surface_acpi_notify.c b/drivers/platform/surface/surface_acpi_notify.c > index 44e317970557..50500e562963 100644 > --- a/drivers/platform/surface/surface_acpi_notify.c > +++ b/drivers/platform/surface/surface_acpi_notify.c > @@ -355,7 +355,8 @@ static u32 san_evt_bat_nf(struct ssam_event_notifier *nf, > INIT_DELAYED_WORK(&work->work, san_evt_bat_workfn); > work->dev = d->dev; > > - memcpy(&work->event, event, sizeof(struct ssam_event) + event->length); > + work->event = *event; > + memcpy(work->event.data, event->data, event->length); > > queue_delayed_work(san_wq, &work->work, delay); > return SSAM_NOTIF_HANDLED; > -- > 2.34.1 >