Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp724106rdb; Thu, 19 Oct 2023 18:24:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuMkwTTD9kTsSMrL+IEBS2ilVfAzSl4aWIO3yQp3+1TVIAusNXArk7cwCzHqoEie+8MJGv X-Received: by 2002:a05:6808:983:b0:3af:585:402a with SMTP id a3-20020a056808098300b003af0585402amr469449oic.39.1697765067750; Thu, 19 Oct 2023 18:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697765067; cv=none; d=google.com; s=arc-20160816; b=MFkhyeIIvFLHQEpLFYMkLrgVIE9xe5eNPSnDkyTSjORFcfFZqGfZHq3+/iy8cHCey4 En6a54nqJZemrhQp/9Z0ncH2AhvYEHEkKS7t6luJ/HAZ+UahV65Ti9xHNeTZA8pzfBHN IKBQNaBurOxnA5pdShXEpMUkb21cQvrbRWl8mo69OHGr3TfE/qOs/VLRG4JyIQoB7SKP zzma6rfvOVkPw6UGUB7oKPeSZ8tCYBdkngjNIeDuM1/JAKNpryugNzGRbOPyObp5IYv6 kpbLWhCLjWwgV36U5IO4+j2q/b7AtOqQe1UjdYuke7U5LRwi+WqOnCJTRxRwbNHM3Dw5 Oisw== 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=svgRlD+xMxXKSNv1D21nXe/Ukb4M7OikQcdxYN6vhEQ=; fh=3HdGjPWOzsvI21Hp5D1/vemgKBbzRsnSXsYIIs1xj6c=; b=UMxg9tWDSNfz0m635k7xsYZavcm8loTFAYIVqzleHCqk1QZCQxOGoyzQLBKhqL6m7N jFck0WpvDK2tiXOs6mEpIawXWuNApUprY2aBMObVhyLa9BBAPdVG0V7nT39dc4u31Bc4 9SPUzX4qKKpc+sXwk4fPCc0Eo4OEOekVbb4ECy7Pa/i0AQ+p5D+LuftoVv3XqVepT3k7 7grr3Y8wG3/P5wZJ1poe/7AQxFsRI+oHjoWdvLJ1icfGuY7co+BhxmHdioqKgZD5+Das 2NG7zz/+428LJ0th9CvuIIHTaw0supVaEebSk0Lm/qoEKswTM6xRLe7NA14JzWTjczHH 3nrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="E6w/HQLu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id x21-20020aa79575000000b006b4319c78efsi801619pfq.389.2023.10.19.18.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 18:24:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="E6w/HQLu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 50C2F8095430; Thu, 19 Oct 2023 18:24:12 -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 S1346758AbjJTBVm (ORCPT + 99 others); Thu, 19 Oct 2023 21:21:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346768AbjJTBVk (ORCPT ); Thu, 19 Oct 2023 21:21:40 -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 5A119116 for ; Thu, 19 Oct 2023 18:21:38 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7bbe0a453so3786397b3.0 for ; Thu, 19 Oct 2023 18:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697764897; x=1698369697; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=svgRlD+xMxXKSNv1D21nXe/Ukb4M7OikQcdxYN6vhEQ=; b=E6w/HQLu+MM7ZPt5y0dka0jHHkkNewlbZNJFvK/oeRDHncOpdSXgod5JH2BVF8wm9h MPiXB70QD9hXN4nxMNLkDxblaJ0lYMB2LfxHA4faV+1OUfPKiBA8qXnqVkJEdWdRBxJO NKIVD2OGfOua6m9uj0A32Wc0LulJ8aiBredMlKg9rH6if+/OCq82VeUwAg7FcMo0Wiof WCKzy9DmqJepUD/ycFXd0/xqSjiTeC1/HjxGGIji9TKXofO0ba42Cj8t0+0H1aH+pugL 7foHYl9Jcz5wcD2qAd7oyEJKpjw+RAKYIJiERoU3xeLgPgpxtVaS8g3BaMtuakRR7Azp ldbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697764897; x=1698369697; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=svgRlD+xMxXKSNv1D21nXe/Ukb4M7OikQcdxYN6vhEQ=; b=Do5lh+iJi1vENBCX2PPO/w8OH/m5EInC0T+tLrpYzL2zTZqRZazohSkSio8Z+KQqHu V6muh3CbrT2zeHaFoeOjTtWCUVhWQoB9LBtRyC91wflXCxARkH7nN71XRiMf8w9Gjxzv +h+4hHQ8T2XOkjMzFa1khV7t4UKMTAJvb8ngm/c0hNYBPAGy4qcgxqtrHc3k62Wt7pVV GUZRMNEYPpPG5J2heScZh2a8rE3L2OmwjrGXJJp0GX0hMsPSno7Xwwr+wnZ0bsQJMe+R eCCVLgaJcaFlk04Nx7eeABzkYbNArDxbx/mB8PAoREcJ0DmtW6Jy1+5kUyt7SILEQxzB 7QTA== X-Gm-Message-State: AOJu0YzDdS3FGoK/NL3CHnAsE7IJi6+ac6JwptunpAnf+/M/J6Yaq856 ujPE/VlnLBpmD4ggrRSBvvwbiP4Wo9g= X-Received: from hhhuuu.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:c80]) (user=hhhuuu job=sendgmr) by 2002:a5b:b06:0:b0:d9a:3a26:fb56 with SMTP id z6-20020a5b0b06000000b00d9a3a26fb56mr9102ybp.2.1697764897525; Thu, 19 Oct 2023 18:21:37 -0700 (PDT) Date: Fri, 20 Oct 2023 01:21:32 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231020012132.100960-1-hhhuuu@google.com> Subject: [PATCH v2] 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 , stable@vger.kernel.org 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]); Thu, 19 Oct 2023 18:24:12 -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") Cc: stable@vger.kernel.org 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.758.gaed0368e0e-goog