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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04635C32771 for ; Sat, 24 Sep 2022 04:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233318AbiIXE2R (ORCPT ); Sat, 24 Sep 2022 00:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233053AbiIXE2N (ORCPT ); Sat, 24 Sep 2022 00:28:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21332F8C04; Fri, 23 Sep 2022 21:28:13 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B17C660A73; Sat, 24 Sep 2022 04:28:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 078E9C433D6; Sat, 24 Sep 2022 04:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663993692; bh=86eW6iIqE0bM9Xt04DpkiC+DSve+XgiN712S/FIk0CI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=k9BS9Az+Bf6cGWLFRHh1FvsgvpmrpzfqXc2HNs2RJbdTxTmxspK5NUKHb4Kh64oQR Sfj890V+mJJxCXY7jCadT/JV9s5fK9TMMGPKyNT3J8R6wUNhCPJKFS9ebeTYwT4PyL 1eRfvCbuRedXzCY42rWYrbak1Mb8/yvTcLghSv6URJKjVe2qN+7FCduvb5AzK2VBo3 CROnPmPdIudYPRyepAzJHF7sxxcd8pm33DGCBPCtu6LW1sqaupTet1iX3slgXw9RNB XmeBd9nuKOEW5qOeyVnSqvVpd0kSZZ/FCEqgl/S8oA6AzB3Li05izfqkBaR4d46kOl +8KN69wSExZOg== Date: Fri, 23 Sep 2022 23:28:05 -0500 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Krzysztof Kozlowski , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] NFC: hci: Split memcpy() of struct hcp_message flexible array Message-ID: References: <20220924040835.3364912-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220924040835.3364912-1-keescook@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 23, 2022 at 09:08:35PM -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. This > split already existed for the "firstfrag" case, so just generalize the > logic further. > > [1] https://lore.kernel.org/linux-hardening/20220901065914.1417829-2-keescook@chromium.org/ > > Cc: Krzysztof Kozlowski > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: netdev@vger.kernel.org > Reported-by: "Gustavo A. R. Silva" > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks! -- Gustavo > --- > net/nfc/hci/hcp.c | 12 +++++------- > 1 file changed, 5 insertions(+), 7 deletions(-) > > diff --git a/net/nfc/hci/hcp.c b/net/nfc/hci/hcp.c > index 05c60988f59a..4902f5064098 100644 > --- a/net/nfc/hci/hcp.c > +++ b/net/nfc/hci/hcp.c > @@ -73,14 +73,12 @@ int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe, > if (firstfrag) { > firstfrag = false; > packet->message.header = HCP_HEADER(type, instruction); > - if (ptr) { > - memcpy(packet->message.data, ptr, > - data_link_len - 1); > - ptr += data_link_len - 1; > - } > } else { > - memcpy(&packet->message, ptr, data_link_len); > - ptr += data_link_len; > + packet->message.header = *ptr++; > + } > + if (ptr) { > + memcpy(packet->message.data, ptr, data_link_len - 1); > + ptr += data_link_len - 1; > } > > /* This is the last fragment, set the cb bit */ > -- > 2.34.1 >