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=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 A02CEC433E0 for ; Mon, 22 Jun 2020 21:04:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B4DF2073E for ; Mon, 22 Jun 2020 21:04:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ILThu+fB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730176AbgFVVEH (ORCPT ); Mon, 22 Jun 2020 17:04:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730418AbgFVVEG (ORCPT ); Mon, 22 Jun 2020 17:04:06 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98643C061797 for ; Mon, 22 Jun 2020 14:04:06 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ga6so439483pjb.1 for ; Mon, 22 Jun 2020 14:04:06 -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:in-reply-to; bh=XaQAHgI/fJz5n4PH9+AAQxpUaFNfDOAFJjIvvuWc6mg=; b=ILThu+fBeQLbDkY3Saa7Zr6fXvZla6p/mhaacfaAod5Ou2LCXGVY9rmI/SQ12/gRGw 0OyvuZwHPdhHMhqZNfaygaAuqkjJxQw9ecwhpY877rYeLJOYo7K1LFnWVKMlDLVDvRVU aO7im+xhoBSS7Rfzh9EnHnbqHF0AGGKdOIZCs= 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:in-reply-to; bh=XaQAHgI/fJz5n4PH9+AAQxpUaFNfDOAFJjIvvuWc6mg=; b=b5phadgcvGgMIJM49D+roD1R99uOid/zWnv830SDJjMxePKOD5kxdfmAq+6Q710R87 WIOi0A91wCGSHktgCerZR0tK/UJZmemdXa53FVzw9oFgrrsf6nIkY2OeE3wh+P2TB4aU zu7Czut6xhHqGVGGKLm6512AG25Wf0VIIoY/Z1FOSUycw50AY/z2DYNgOmBXOsys8dLo ldI9RAW+xYzdi9McLGNc4Tz38Y1rrFjyDztdCLo8pnKertl3yAq2uqSdT073ApqlPW14 afRYdaHf7JJs/dRDOdoxQ9xtxrSYzDEM9CA6S/hWGqPoRyDbdGjX7/DZ7UZt4S6W4zW4 KWLQ== X-Gm-Message-State: AOAM531x/LwX30/8jrP6bRe4nYuBf/bFdP4PV7rimFpEH54mQPZujM5C hGRRj3hY731KZLnFApIlGMcqzw== X-Google-Smtp-Source: ABdhPJxa2RKG+txMKUm/MEMBUFpa2Kv9XKoAQ0+Lw2FAoqT0JOWKLV1rtyBoAVQcAiWWStDNJ+p+nQ== X-Received: by 2002:a17:902:b942:: with SMTP id h2mr20581705pls.163.1592859846012; Mon, 22 Jun 2020 14:04:06 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d2sm10586968pfc.1.2020.06.22.14.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 14:04:05 -0700 (PDT) Date: Mon, 22 Jun 2020 14:04:04 -0700 From: Kees Cook To: Nick Desaulniers Cc: LKML , Linus Torvalds , Miguel Ojeda , Alexander Potapenko , Joe Perches , Andy Whitcroft , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, b43-dev@lists.infradead.org, Network Development , Linux Doc Mailing List , linux-wireless , linux-ide@vger.kernel.org, linux-clk@vger.kernel.org, linux-spi@vger.kernel.org, Linux Memory Management List , clang-built-linux Subject: Re: [PATCH v2 04/16] b43: Remove uninitialized_var() usage Message-ID: <202006221403.EEAD37E94B@keescook> References: <20200620033007.1444705-1-keescook@chromium.org> <20200620033007.1444705-5-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Mon, Jun 22, 2020 at 10:04:18AM -0700, Nick Desaulniers wrote: > On Fri, Jun 19, 2020 at 8:30 PM Kees Cook wrote: > > > > Using uninitialized_var() is dangerous as it papers over real bugs[1] > > (or can in the future), and suppresses unrelated compiler warnings (e.g. > > "unused variable"). If the compiler thinks it is uninitialized, either > > simply initialize the variable or make compiler changes. As a precursor > > to removing[2] this[3] macro[4], just initialize this variable to NULL. > > No later NULL deref is possible due to the early returns outside of the > > (phy->rev >= 7 && phy->rev < 19) case, which explicitly tests for NULL. > > > > [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/ > > [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/ > > [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/ > > [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/ > > > > Fixes: 58619b14d106 ("b43: move under broadcom vendor directory") > > Signed-off-by: Kees Cook > > I see three total uses of uninitialized_var() in this file, do we want > to eliminate all of them? This is the only one that needed an explicit initialization -- all the others are handled in the treewide patch. I *could* split it out here, but I found it easier to keep the "no op" changes together in the treewide patch. -Kees > > > --- > > drivers/net/wireless/broadcom/b43/phy_n.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/net/wireless/broadcom/b43/phy_n.c b/drivers/net/wireless/broadcom/b43/phy_n.c > > index c33b4235839d..46db91846007 100644 > > --- a/drivers/net/wireless/broadcom/b43/phy_n.c > > +++ b/drivers/net/wireless/broadcom/b43/phy_n.c > > @@ -4222,7 +4222,7 @@ static void b43_nphy_tx_gain_table_upload(struct b43_wldev *dev) > > u32 rfpwr_offset; > > u8 pga_gain, pad_gain; > > int i; > > - const s16 *uninitialized_var(rf_pwr_offset_table); > > + const s16 *rf_pwr_offset_table = NULL; > > > > table = b43_nphy_get_tx_gain_table(dev); > > if (!table) > > -- > > -- > Thanks, > ~Nick Desaulniers -- Kees Cook From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Date: Mon, 22 Jun 2020 14:04:04 -0700 Subject: [PATCH v2 04/16] b43: Remove uninitialized_var() usage In-Reply-To: References: <20200620033007.1444705-1-keescook@chromium.org> <20200620033007.1444705-5-keescook@chromium.org> Message-ID: <202006221403.EEAD37E94B@keescook> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Nick Desaulniers Cc: LKML , Linus Torvalds , Miguel Ojeda , Alexander Potapenko , Joe Perches , Andy Whitcroft , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, b43-dev@lists.infradead.org, Network Development , Linux Doc Mailing List , linux-wireless , linux-ide@vger.kernel.org, linux-clk@vger.kernel.org, linux-spi@vger.kernel.org, Linux Memory Management List , clang-built-linux On Mon, Jun 22, 2020 at 10:04:18AM -0700, Nick Desaulniers wrote: > On Fri, Jun 19, 2020 at 8:30 PM Kees Cook wrote: > > > > Using uninitialized_var() is dangerous as it papers over real bugs[1] > > (or can in the future), and suppresses unrelated compiler warnings (e.g. > > "unused variable"). If the compiler thinks it is uninitialized, either > > simply initialize the variable or make compiler changes. As a precursor > > to removing[2] this[3] macro[4], just initialize this variable to NULL. > > No later NULL deref is possible due to the early returns outside of the > > (phy->rev >= 7 && phy->rev < 19) case, which explicitly tests for NULL. > > > > [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider at google.com/ > > [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw at mail.gmail.com/ > > [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg at mail.gmail.com/ > > [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA at mail.gmail.com/ > > > > Fixes: 58619b14d106 ("b43: move under broadcom vendor directory") > > Signed-off-by: Kees Cook > > I see three total uses of uninitialized_var() in this file, do we want > to eliminate all of them? This is the only one that needed an explicit initialization -- all the others are handled in the treewide patch. I *could* split it out here, but I found it easier to keep the "no op" changes together in the treewide patch. -Kees > > > --- > > drivers/net/wireless/broadcom/b43/phy_n.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/net/wireless/broadcom/b43/phy_n.c b/drivers/net/wireless/broadcom/b43/phy_n.c > > index c33b4235839d..46db91846007 100644 > > --- a/drivers/net/wireless/broadcom/b43/phy_n.c > > +++ b/drivers/net/wireless/broadcom/b43/phy_n.c > > @@ -4222,7 +4222,7 @@ static void b43_nphy_tx_gain_table_upload(struct b43_wldev *dev) > > u32 rfpwr_offset; > > u8 pga_gain, pad_gain; > > int i; > > - const s16 *uninitialized_var(rf_pwr_offset_table); > > + const s16 *rf_pwr_offset_table = NULL; > > > > table = b43_nphy_get_tx_gain_table(dev); > > if (!table) > > -- > > -- > Thanks, > ~Nick Desaulniers -- Kees Cook