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 DAA66C433FE for ; Thu, 5 May 2022 03:14:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240595AbiEEDRm (ORCPT ); Wed, 4 May 2022 23:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232469AbiEEDRl (ORCPT ); Wed, 4 May 2022 23:17:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5067920F66; Wed, 4 May 2022 20:14:03 -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 ams.source.kernel.org (Postfix) with ESMTPS id EB3A5B82794; Thu, 5 May 2022 03:14:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED32EC385A5; Thu, 5 May 2022 03:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651720440; bh=fgYShDk8J/LH7fRewSMC+BYKPB5NxskQkpkXs8hqxDs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Gu8BTaS6QcvN1Zcekn09aNMpiKrZ9CwVxhA+jmfPxjC756WBiUYF+PQtSaX3xzv0C WyAvNADizjYRGzBFni+0HqRpXeOUVOjg8WES8/iUOZ8+MICEO2tYZXqGIzVrC+pYR9 5KzVzpyoiK32DuYzLzdKP9OiZR1Hij1i3gS4meXMP7qH9jTEdHWyAzkc6zDcSmGDmN xREyDvy+jPrCIfl6VNibDFXcg8GC6ehZ9/X7cmlyVM9TeWwySYbGw/TYJ6hkWeNJGo ZYbThIgvL41D63EC8IcDOPCl88QI75i06nKBS27oAmvBtMYTCkgvoiVLylSEPGNCht H9zuPE6rjSBNg== Date: Wed, 4 May 2022 20:13:58 -0700 From: Jakub Kicinski To: Kees Cook Cc: Raju Rangoju , kernel test robot , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, stable@vger.kernel.org, Heiner Kallweit , Bjorn Helgaas , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] net: chelsio: cxgb4: Avoid potential negative array offset Message-ID: <20220504201358.0ba62232@kernel.org> In-Reply-To: <20220503144425.2858110-1-keescook@chromium.org> References: <20220503144425.2858110-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, 3 May 2022 07:44:25 -0700 Kees Cook wrote: > Using min_t(int, ...) as a potential array index implies to the compiler > that negative offsets should be allowed. This is not the case, though. > Replace min_t() with clamp_t(). Fixes the following warning exposed > under future CONFIG_FORTIFY_SOURCE improvements: > Additionally remove needless cast from u8[] to char * in last strim() > call. > > Reported-by: kernel test robot > Link: https://lore.kernel.org/lkml/202205031926.FVP7epJM-lkp@intel.com > Fixes: fc9279298e3a ("cxgb4: Search VPD with pci_vpd_find_ro_info_keyword()") > Fixes: 24c521f81c30 ("cxgb4: Use pci_vpd_find_id_string() to find VPD ID string") Is it needed in the current release? > Cc: Raju Rangoju > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: netdev@vger.kernel.org > Cc: stable@vger.kernel.org > Signed-off-by: Kees Cook > --- > drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c > index e7b4e3ed056c..f119ec7323e5 100644 > --- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c > +++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c > @@ -2793,14 +2793,14 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) > goto out; > na = ret; > > - memcpy(p->id, vpd + id, min_t(int, id_len, ID_LEN)); > + memcpy(p->id, vpd + id, clamp_t(int, id_len, 0, ID_LEN)); The typing is needed because of the enum, right? The variable is unsigned, seems a little strange to use clamp(int, ..., 0, constant) min(unsigned int, ..., constant) will be equivalent with fewer branches. Is it just me? > strim(p->id); > - memcpy(p->sn, vpd + sn, min_t(int, sn_len, SERNUM_LEN)); > + memcpy(p->sn, vpd + sn, clamp_t(int, sn_len, 0, SERNUM_LEN)); > strim(p->sn); > - memcpy(p->pn, vpd + pn, min_t(int, pn_len, PN_LEN)); > + memcpy(p->pn, vpd + pn, clamp_t(int, pn_len, 0, PN_LEN)); > strim(p->pn); > - memcpy(p->na, vpd + na, min_t(int, na_len, MACADDR_LEN)); > - strim((char *)p->na); > + memcpy(p->na, vpd + na, clamp_t(int, na_len, 0, MACADDR_LEN)); > + strim(p->na); > > out: > vfree(vpd);