Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp146724rdb; Wed, 18 Oct 2023 23:06:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbThM0PnTLctQ0Prd/jwG6Rrfl5XTbBgz6Ly9hNdse0Kiw09IU9o4akfNl4w1FQnvqNHtx X-Received: by 2002:a17:902:f385:b0:1c7:365a:566d with SMTP id f5-20020a170902f38500b001c7365a566dmr1048588ple.66.1697695594856; Wed, 18 Oct 2023 23:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697695594; cv=none; d=google.com; s=arc-20160816; b=Mep7uLjG08QPmj21DDsR4jfChU6oTNhDAPyGSMG4e8IL+QKZLiHgUNccPm56k9hQ96 3vAJIAhslSo2IJNMXs/ueUq9Ipfy64q1Oa03pIH02VC15RRskV2ofvw/9lfBue5/Ndpj T6vtpWCJHPQBeSurFIxoMHEZ7MU5++o0jyLrWiU5skufBFFhN6nnP9DfS0b+SmmCea6j +fP9qznMjyWB4Rw58mYTpcGEqz/S35KGJunqAXmkm/baTzredRgboaHFhQ7aXUrO5ei7 Hkg9/47d1EloI2lX26e4x46Myu1gzweVWEV1iLq+LFBiacqX948TeFYgePkCxnRnwU6H Pu7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=Lr68DklHqj74TxP0eigSuVpguDEeRxq0NgDtMHIH/oI=; fh=7vaUQFYXbNQu9iT9p65/kMn3GdNnjfB7ndHISAb9PHA=; b=HX0fFgJ2AlarsuFpIR6BS+wm7ry6tVYAprKgIN2zFanpiEI70sig0RptEjFanYuRad cEabXniXHgoOI+JEJ3MpvJtK+Q+Rwg4czvSoL5tvCOiHJ6gLZzjKDq0hODJeW3DMREHr b+QyLft6xgj0EbFI7jASG8Sg3/MjrKaVB3hgpjT7ACP/tZdHvx4UFUEZmVz4EK9aqhxY 4Yhiw8Q9tPfZ3iy0cBFN7lbnF/WjrvpmwjMGfRdc+SmwoxS3X1pNLgmhKzfsXnjJjekT Y7IgMPWcQBZZD5ub522XHQnx9exm9Vc1rVKX8+uSYMJRo5CMWO9Xbt2/TLC+AHAFS9OZ z96w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yI1u9WmY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id q5-20020a170902a3c500b001c09d893c94si1473200plb.612.2023.10.18.23.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 23:06:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yI1u9WmY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C8E2D822D560; Wed, 18 Oct 2023 23:06:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbjJSGG0 (ORCPT + 99 others); Thu, 19 Oct 2023 02:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjJSGGY (ORCPT ); Thu, 19 Oct 2023 02:06:24 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA132116 for ; Wed, 18 Oct 2023 23:06:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a839b31a0dso87640137b3.0 for ; Wed, 18 Oct 2023 23:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697695582; x=1698300382; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Lr68DklHqj74TxP0eigSuVpguDEeRxq0NgDtMHIH/oI=; b=yI1u9WmYCCKp+URianPUqDBeVnJcpjK+b/l1y7cshee5UpH12W5ZZFclN9xChI+5hA wmJ8tgei8Vjg/57XbexbFhslugLDaQQkaMmai6/3nQQpXNBL57MdcF2syWViEdrN762C ioTh2L+skWoSH75+a8NkCbOZ7rM7DsergA6R++V9/w4MjLwoNSA58NgTDIi1m7nproHL gDhSuqHwsTEDwWBacRxb4QBDMml355+b9tKr+zdyo1Az0QirC5WgjVXHuIqq5KomwBAC nUCQQF/8/vW2FkC9H7Tw5nA2xNnm5CRCUzdgpyHL8Qd+g3+ux3wcY3gSpJcHVcU6xxMZ IIOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697695582; x=1698300382; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Lr68DklHqj74TxP0eigSuVpguDEeRxq0NgDtMHIH/oI=; b=NxVyGB0GQz2Wpnvdmzx/HSnchxBeW6adCEzXvzB+n6X0rTlaAyKMX0e3XstuiPSlkZ ZOz9TG8wceW/f7W6iirIqpjAZ16KB77JmPABKdmLkrMDX32/LiXSWoSQCxHuSunFV4dW xvVvdp4A3inpimqmJ8I9G55kFtTxLgzRxqj08mV2qkI/abRI9/phhNXKrRjHaDFJoJ1O u4FWT47arNSiObAhvBHxMxH5u3UH9/7nRE58U6PetdPFUMRnutXFSSquECAXe3wHq2/l IgBOFtQl2GLIQKLTfqG8mkSexlidV1BLTMZLMDmJXN82Sp4jCeqP4Ba4yihG7iO28yZU yI6A== X-Gm-Message-State: AOJu0Yx5/zcFLI1kc+9fLtYUAszue8iEoBgxGpj79VQwsEFeXNdHPl9H OZVAUbfCZYRLaBSloaGyozblCMh+yx4= X-Received: from hhhuuu.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:c80]) (user=hhhuuu job=sendgmr) by 2002:a81:92c6:0:b0:5a7:afd5:1cb1 with SMTP id j189-20020a8192c6000000b005a7afd51cb1mr31144ywg.1.1697695581761; Wed, 18 Oct 2023 23:06:21 -0700 (PDT) Date: Thu, 19 Oct 2023 06:06:16 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019060616.1988631-1-hhhuuu@google.com> Subject: [PATCH] usb: typec: tcpm: Fix NULL pointer dereference in tcpm_pd_svdm() From: Jimmy Hu To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: kyletso@google.com, badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jimmy Hu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 18 Oct 2023 23:06:32 -0700 (PDT) It is possible that typec_register_partner() returns ERR_PTR on failure. When port->partner is an error, a NULL pointer dereference may occur as shown below. [91222.095236][ T319] typec port0: failed to register partner (-17) ... [91225.061491][ T319] Unable to handle kernel NULL pointer dereference at virtual address 000000000000039f [91225.274642][ T319] pc : tcpm_pd_data_request+0x310/0x13fc [91225.274646][ T319] lr : tcpm_pd_data_request+0x298/0x13fc [91225.308067][ T319] Call trace: [91225.308070][ T319] tcpm_pd_data_request+0x310/0x13fc [91225.308073][ T319] tcpm_pd_rx_handler+0x100/0x9e8 [91225.355900][ T319] kthread_worker_fn+0x178/0x58c [91225.355902][ T319] kthread+0x150/0x200 [91225.355905][ T319] ret_from_fork+0x10/0x30 Add a check for port->partner to avoid dereferencing a NULL pointer. Fixes: 5e1d4c49fbc8 ("usb: typec: tcpm: Determine common SVDM Version") Signed-off-by: Jimmy Hu --- drivers/usb/typec/tcpm/tcpm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 6e843c511b85..792ec4ac7d8d 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -1625,6 +1625,9 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev, if (PD_VDO_VID(p[0]) != USB_SID_PD) break; + if (IS_ERR_OR_NULL(port->partner)) + break; + if (PD_VDO_SVDM_VER(p[0]) < svdm_version) { typec_partner_set_svdm_version(port->partner, PD_VDO_SVDM_VER(p[0])); -- 2.42.0.655.g421f12c284-goog