Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4964214rwe; Mon, 17 Apr 2023 23:17:31 -0700 (PDT) X-Google-Smtp-Source: AKy350YoKdoJf08Bbt1uXiRqooRkL4rp8Y3zPI+Fq9W0yh6oP+E2d+rXyoqOd0ALUQOtxTSNlbin X-Received: by 2002:a05:6a20:7350:b0:ef:d300:3d94 with SMTP id v16-20020a056a20735000b000efd3003d94mr7622960pzc.26.1681798651167; Mon, 17 Apr 2023 23:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681798651; cv=none; d=google.com; s=arc-20160816; b=jG4zMN4jeJ0BwydmluA+cFWvZ4zz4TaZpQ6P8OpAQSI134yx3gzlT+jIs8VtNwQrsw Ua7QPFrVcSKat78imywPmQFsYwjqdRhSOSr9ioL/JgYwV4TzwU7aClR/ETArDAhu3YLb M2Od6OgSBx3af/6z4jQ2E8Wo7DA9wEA1K/u10sTn+TrRdEzi19/6CjHZLnSl4yxaTAl3 9q/BMTdr59x2Y2TheSe9/UNsteoTD6+EtjedDcKlMAr04HbwwWr8xlmWdIo9iJquOMWM MVjmicrKxEaaa2TCsZwd65qteDEWGFtHNshFLYrzat08Y1NIUusAipuPdsLBGf2MTCxA b6Ag== 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=y+aOxbZsGDtl4ySLWGn4f0Uaxr/no0MVyRiTJHoNp7Y=; b=hWvRfA6Zdswl4n7VnivQouhqmW0uRQk4IgG4WtfZlUVcFACHGcf/dspB032tvZPouL bcDRhEKugG7KibakwbV/ahfFDzBepW4qyRBGVMTlYrG9Jf/b3P425nieDitZ3w4MoUb5 aq0jdCNUVk1MjjLCy1SjKbyLlnicSmS4bcae7L6Vts7VGijvTFV1lrf/ejTYs1ZDKCas CuSCNo174lJPH+/fZ1/+fuTfLcgHkJwQmhWDVudzU10LuZXjcgt4F2wWitk1oyPI55+k 1v7M9Hbr58oQmU5j6/jfhP9jR5WUEb0Q2xY8EDY3q6mU9J7i4tNy/i+BEwWOu5PrAiR1 ZrlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cBWc+iUp; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i30-20020a63585e000000b0050bea56f69asi13980855pgm.735.2023.04.17.23.17.19; Mon, 17 Apr 2023 23:17:31 -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=@linuxfoundation.org header.s=korg header.b=cBWc+iUp; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230257AbjDRGQ0 (ORCPT + 99 others); Tue, 18 Apr 2023 02:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbjDRGQZ (ORCPT ); Tue, 18 Apr 2023 02:16:25 -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 6596F468E; Mon, 17 Apr 2023 23:16:24 -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 E6B2162CFF; Tue, 18 Apr 2023 06:16:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D91A2C433D2; Tue, 18 Apr 2023 06:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1681798583; bh=jhLgevMsu3orYKO8vXOQraEaEey0j/z79iJrpMSNtIg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cBWc+iUpVGUGQD/aR4PEGnf83S8CFqvFgivV5AVttJOkhmWpqpFO+1pBrFf+kh2sT f3cFO9ha6aVk1uMbvp7SDR/vnBuJR6xUcTcQpoEyMPFkW2Oof4PmA4BHiedl9n2Uct wbFRNzPrH9DRQ05og/8hRasp1Ka5lYjnsACnXV+Q= Date: Tue, 18 Apr 2023 08:16:20 +0200 From: Greg Kroah-Hartman To: Maxim Korotkov Cc: Heikki Krogerus , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: Re: [PATCH] usb: typec: fix potential NULL dereference Message-ID: References: <20230417195003.19504-1-korotkov.maxim.s@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230417195003.19504-1-korotkov.maxim.s@gmail.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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, Apr 17, 2023 at 10:50:03PM +0300, Maxim Korotkov wrote: > The pointer 'adev' was being dereferenced before being checked for NULL > in the 'type_alt mode_enter()' and 'type_alt mode_exit()' functions. > Although this is a hypothetical issue, it's better to move the pointer > assignment after the NULL check to avoid any potential problems. > > Found by Linux Verification Center with Svace static analyzer. > > Fixes: 8a37d87d72f0 ("usb: typec: Bus type for alternate modes") > Signed-off-by: Maxim Korotkov > --- > drivers/usb/typec/bus.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c > index 098f0efaa58d..ae0aca8f33db 100644 > --- a/drivers/usb/typec/bus.c > +++ b/drivers/usb/typec/bus.c > @@ -125,13 +125,16 @@ EXPORT_SYMBOL_GPL(typec_altmode_notify); > */ > int typec_altmode_enter(struct typec_altmode *adev, u32 *vdo) > { > - struct altmode *partner = to_altmode(adev)->partner; > - struct typec_altmode *pdev = &partner->adev; > + struct altmode *partner; > + struct typec_altmode *pdev; > int ret; > > if (!adev || adev->active) > return 0; > > + partner = to_altmode(adev)->partner; > + pdev = &partner->adev; As you point out, the original code is still fine here, we check before we actually use these values. Also, can adev every actually be NULL? In looking at the code paths, I can't see how that could happen. thanks, greg k-h