Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp129997lqc; Thu, 7 Mar 2024 12:23:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU00Gr0s6cg/+kAFFtN4GmBLhyr9DiMN06azqWvVs9JxmvFgJ7t+ni0/Mcy1Gij2Rjvd3qdAXKCh+cizUKBgrd59GCnWrComr5Reoragw== X-Google-Smtp-Source: AGHT+IHQaOlijI8h2BUnJeQr+4tbTz2v+kzWOXEzEelqpc7Cdz0f+ygGIsTJVXBNvK/R4KP1ynTF X-Received: by 2002:a05:6a00:880e:b0:6e6:4cdf:743a with SMTP id ho14-20020a056a00880e00b006e64cdf743amr5263072pfb.32.1709842985312; Thu, 07 Mar 2024 12:23:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709842985; cv=pass; d=google.com; s=arc-20160816; b=ELFiGJ6/q7vzFX+3RHqtNk+c2suLxGXAf5bQ169SlAtU9OsgVOSMqQnm5wUN5Uz/wM N5hdOtow/i1bisMUWeuujjRf2y3RqvRqIzwUSgdJbPgJ6ReEcGrAzIOVHxBgRgKE9EMk a++onmX2WeacvER7+jRBo5FIvyJm/lqHf1h7ePCarvVSarAndMfEpiaw5nC8ajK09pMO 1b3/Z6CRCQKHrTUmy9Cg/H6h2WlSw80tO7Md4Nl2W+a2rH+yrQcFjecM/zvmiVfvcu42 ySUlgAmyXOk3DvwjeLEmLOOTss95cSipKSyg1YKNZX9oMsJOLNWkgTsyzs6BA16oKaqD v7mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gj7oOuwiWTs3D3sNhRN8A6+8rBskvEU4W316SxnrZUQ=; fh=YobbhIDo7pkk/ycE34Zk73csQk8bW8kOWmzRaQaJdfU=; b=YqzzAki7jhbbBhOQAdGyCVFvu0I31K34ZsBWXrqHaqUXzn0WD5LPo2bW8p18Z9OE+X O0mwimvGqn0o8RJgqD1jUAe5v+pT1FHY5DSXh0bZLTvW88v9yKR3HJW8aMjiwnIKDHen cmCnS0CRvP1f6GHjruu6nboyS5Puqa/GG6NwQEKWLf8vZi9U42kljuFy7Sx2PNNgzEX8 wzHlZPleQzpzl2Op04AXKTCvNg8LySvIFk5QOQcXZn+NaTSEyPxTMWKPwyW6fETPLYj+ day5QqV028LzgKiQL8kiFzzyx+XWP5hSrz1RNgKCqU+1EzN32Y7Pqd+vtD2HT51XTxWg 7f/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Z9qYltEc; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-96183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96183-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y40-20020a056a00182800b006e6209b95afsi8421008pfa.338.2024.03.07.12.23.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:23:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Z9qYltEc; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-96183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96183-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EB01F282411 for ; Thu, 7 Mar 2024 20:23:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2E0E13956D; Thu, 7 Mar 2024 20:22:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Z9qYltEc" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64F201369A4 for ; Thu, 7 Mar 2024 20:22:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709842972; cv=none; b=qQoKjwZG13ByZDJGHBT/baVWJWum0AwtgD7j0TLoKkjmqK78Mvu9Fmqyj3zHSJQv6PMV0mLBIX3RfEI5Po95sN7lKh/XSSIg1zX7UcMmxfU54GT/MNtMb5Kr70mpxKxUbUNMJWPrPM2AqvDgM+Vntqwo76B+tcwopuug4QebasE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709842972; c=relaxed/simple; bh=rsRY4KHhOJ11hCtZ8v0Bh9J/hZ5MuHy4e/+hy4b7p7c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fu01TK1tlv8BZp89jVgp7862Zb+hLyS74LGoIbodXwV6xf/ITFyWNB4Sz1bB4A/iDMZXpVh9McwHDTzZ30A3Y8VPNa5n4CqC01z15Io8SFmQQtNoQYyA5CzCgIa0ikSttCPHyYhd+3q4X18fYBJQKcMnty26v01HiY9PSrOyyNU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Z9qYltEc; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1dcafff3c50so10238335ad.0 for ; Thu, 07 Mar 2024 12:22:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709842971; x=1710447771; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=gj7oOuwiWTs3D3sNhRN8A6+8rBskvEU4W316SxnrZUQ=; b=Z9qYltEczee533bhL6XcuFl3TuMK+ESAhilan3P4tEKBrRuWu4xMSw2AVzsiGFK//K Iv4JNewp1DzM5TKsoI+f9U+O6uxYMjMrNvITeoy+wMIfZRv7MEcUOrU73oQHCWG8JRim EFrot9hhxqtP59O9lGYQT7iMAetLMkhmdVsb0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709842971; x=1710447771; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gj7oOuwiWTs3D3sNhRN8A6+8rBskvEU4W316SxnrZUQ=; b=bzvOFY3WGf8VTBqmWg/bt/tcQ2b/E4NpFoZG0BYbub2u9R/HVJFbB/m8kE2O2ocuFo Gt4rxH6zdAs5+6P2D7lu4JOEngqwRSsYVhamj59Q+pSTvGSAqkOgu3+L2p8xiRGBOXqm Cdx2QVIGxXx/xj4tfP/N6H2UrxOfEFmF0NYMz5U/PYB58h44zuwNi6isLNCIaNGSLyHo oUxBcRu7t3XUW7Ap62opC2OP8dT4fw4ehrFdLbFeXNtwbv4iEAooHz4c36r/qgdk3nKP s6ye7VrY6H1KR5YMRAobayq2usoO/fB9cRxlisN+hW2EizOsz8MjUCjMghRhhfATzvPI IJwQ== X-Forwarded-Encrypted: i=1; AJvYcCUylt1lgGFMaVJNi/41vlbgPC8mFrSmccuopBYIG8cxQiv2JBDREf+lUO9aTyOMI6hD1SwSmXNPNkIoJg3sjB9bMVChSnccQYkoCKB4 X-Gm-Message-State: AOJu0YyRnQJr9pJVYbo2TF6zNWGGKiMpU33/URaGaYB5hkxp8RmLw0rI ulOfiTq4MUWvOVIKnMQ1MyaY/srR7kaX9J/eTolA5s8kFW7zUW8Xt8IcAyBokQ== X-Received: by 2002:a17:902:e84f:b0:1dc:3c3f:c64b with SMTP id t15-20020a170902e84f00b001dc3c3fc64bmr10989479plg.24.1709842970750; Thu, 07 Mar 2024 12:22:50 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id h14-20020a170902680e00b001dd62b4dd7asm581604plk.47.2024.03.07.12.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:22:50 -0800 (PST) Date: Thu, 7 Mar 2024 12:22:49 -0800 From: Kees Cook To: "Christian A. Ehrhardt" Cc: Jameson Thies , Hans de Goede , Fabrice Gasnier , Neil Armstrong , linux-usb@vger.kernel.org, Benson Leung , Saranya Gopal , Dmitry Baryshkov , Abhishek Pandit-Subedi , Prashant Malani , Heikki Krogerus , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "Gustavo A. R. Silva" , linux-next@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: Coverity: ucsi_check_cable(): Null pointer dereferences Message-ID: <202403071216.DD2F952B@keescook> References: <202403071134.7C7C077655@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Mar 07, 2024 at 09:16:00PM +0100, Christian A. Ehrhardt wrote: > > Hi, > > On Thu, Mar 07, 2024 at 11:34:21AM -0800, coverity-bot wrote: > > Hello! > > > > This is an experimental semi-automated report about issues detected by > > Coverity from a scan of next-20240307 as part of the linux-next scan project: > > https://scan.coverity.com/projects/linux-next-weekly-scan > > > > You're getting this email because you were associated with the identified > > lines of code (noted below) that were touched by commits: > > > > Tue Mar 5 13:11:08 2024 +0000 > > f896d5e8726c ("usb: typec: ucsi: Register SOP/SOP' Discover Identity Responses") > > > > Coverity reported the following: > > > > *** CID 1584245: Null pointer dereferences (FORWARD_NULL) > > drivers/usb/typec/ucsi/ucsi.c:1136 in ucsi_check_cable() > > 1130 } > > 1131 > > 1132 ret = ucsi_register_cable(con); > > 1133 if (ret < 0) > > 1134 return ret; > > 1135 > > vvv CID 1584245: Null pointer dereferences (FORWARD_NULL) > > vvv Passing "con" to "ucsi_get_cable_identity", which dereferences null "con->cable". > > 1136 ret = ucsi_get_cable_identity(con); > > 1137 if (ret < 0) > > 1138 return ret; > > 1139 > > 1140 ret = ucsi_register_plug(con); > > 1141 if (ret < 0) > > > > If this is a false positive, please let us know so we can mark it as > > such, or teach the Coverity rules to be smarter. If not, please make > > sure fixes get into linux-next. :) For patches fixing this, please > > include these lines (but double-check the "Fixes" first): > > This looks like a false positive to me. The code looks like this: > > if (con->cable) > return 0; > [ ... ] > ret = ucsi_register_cable(con) > if (ret < 0) > return ret; > ret = ucsi_get_cable_identity(con); > [ ... ] > > From the con->cable check coverity concludes that con->cable is > initially NULL. Later ucsi_register_cable() initializes con->cable > if successful. Coverity seems to miss this and still thinks that > con->cable is NULL. Then converity correctly notices that > ucsi_get_cable_identity() dereferences con->cable and complains. Ah-ha! Yes, the ucsi_register_cable() check seems to have been missed. I think it's confused by: cable = typec_register_cable(con->port, &desc); if (IS_ERR(cable)) { This isn't IS_ERR_OR_NULL, so it thinks cable might still be NULL, but there's no path through typec_register_cable() where that can be true. Thanks for taking a look! -Kees -- Kees Cook