Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3489628ybi; Mon, 29 Jul 2019 07:26:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTTizas5VJa5/BitdFu0byK446Sp9Bh3KHabhqJVMULfhYyFIKtonLVpsqaOwhMHv6hoLa X-Received: by 2002:a63:494d:: with SMTP id y13mr106353004pgk.109.1564410418962; Mon, 29 Jul 2019 07:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564410418; cv=none; d=google.com; s=arc-20160816; b=0R951E/an+XyBWvgoDOAm9ezIp7qi7v2K71XkVRkEhjPFfI1CUN2DKO2ni98OkBVBx F1trm+pPuyHkRLzMi96LQMIXUfX5hWTE1GfYGSjYiJZoCbl1NzL2F0DYtNYBRKe6jS1y tl7VI1FaCpzaX+x3CIAzaXl5uJrYwfBtGBIBdz4w3VNh2Bvu2t3SWLsuZYivUOZF0xw2 XvcWtKAG0nLLv7NYqtdWklSX4lzI2XFtYO/8kYMITzJ7fSpfPxhW6AaT8OCJLmPNO5n8 H060u/83ZpBBd+u4GRSvMPdHZE5NgZQ0naf15qRLjVHgHuJUNW2150Tydhq/pRck9Lmq CJYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ZYDlBTQmm/aB61Ywlf7DmH7JtenZBA4mtJ4CT84TZ5U=; b=HbSp7mCz/DE6Af7L3UNlUZ+l7C19N9g5J0nQDNp0Ar3X9fS+TZUrDm8RccyoGaQrWN ZyrIiWV8k0Et27a7XPJYaCXaV/D7msl8bD9ke7yn2ZifmAjs0Kucwf7sgZXJ5IX/chOu 6zlXhpowHQUxpi+Jbw7OxfowsSQXu4hK4VGQ07Z2DwbhkFXfJrj1TbhJ3BPHlqbLnE02 PwZd8vRM6eBj+IEbNjuPz7AfUCgP3H4zzIbDf+IhHqe/64anqyIr4DKd3hNZJaC05tKe wKn37jUwE7Y0K+pusaz1/egaWITGLWY6hqMXHfMt72/Ooz3+vTvHgBk0QoBmzSv3xu4x /IKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l69si25955362plb.302.2019.07.29.07.26.43; Mon, 29 Jul 2019 07:26:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728398AbfG2OFB (ORCPT + 99 others); Mon, 29 Jul 2019 10:05:01 -0400 Received: from mga04.intel.com ([192.55.52.120]:45046 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727324AbfG2OFA (ORCPT ); Mon, 29 Jul 2019 10:05:00 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2019 07:05:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,322,1559545200"; d="diff'?scan'208";a="190577036" Received: from kuha.fi.intel.com ([10.237.72.189]) by fmsmga001.fm.intel.com with SMTP; 29 Jul 2019 07:04:57 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Mon, 29 Jul 2019 17:04:57 +0300 Date: Mon, 29 Jul 2019 17:04:57 +0300 From: Heikki Krogerus To: Guenter Roeck , Douglas Gilbert Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] usb: typec: tcpm: Ignore unsupported/unknown alternate mode requests Message-ID: <20190729140457.GC28600@kuha.fi.intel.com> References: <1564029037-22929-1-git-send-email-linux@roeck-us.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="82I3+IH0IqGh5yIs" Content-Disposition: inline In-Reply-To: <1564029037-22929-1-git-send-email-linux@roeck-us.net> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --82I3+IH0IqGh5yIs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Wed, Jul 24, 2019 at 09:30:37PM -0700, Guenter Roeck wrote: > TCPM may receive PD messages associated with unknown or unsupported > alternate modes. If that happens, calls to typec_match_altmode() > will return NULL. The tcpm code does not currently take this into > account. This results in crashes. > > Unable to handle kernel NULL pointer dereference at virtual address 000001f0 > pgd = 41dad9a1 > [000001f0] *pgd=00000000 > Internal error: Oops: 5 [#1] THUMB2 > Modules linked in: tcpci tcpm > CPU: 0 PID: 2338 Comm: kworker/u2:0 Not tainted 5.1.18-sama5-armv7-r2 #6 > Hardware name: Atmel SAMA5 > Workqueue: 2-0050 tcpm_pd_rx_handler [tcpm] > PC is at typec_altmode_attention+0x0/0x14 > LR is at tcpm_pd_rx_handler+0xa3b/0xda0 [tcpm] > ... > [] (typec_altmode_attention) from [] > (tcpm_pd_rx_handler+0xa3b/0xda0 [tcpm]) > [] (tcpm_pd_rx_handler [tcpm]) from [] > (process_one_work+0x123/0x2a8) > [] (process_one_work) from [] > (worker_thread+0xbd/0x3b0) > [] (worker_thread) from [] (kthread+0xcf/0xf4) > [] (kthread) from [] (ret_from_fork+0x11/0x38) > > Ignore PD messages if the asociated alternate mode is not supported. > > Reported-by: Douglas Gilbert > Cc: Douglas Gilbert > Fixes: e9576fe8e605c ("usb: typec: tcpm: Support for Alternate Modes") > Signed-off-by: Guenter Roeck > --- > Taking a stab at the problem. I don't really know if this is the correct > fix, or even if my understanding of the problem is correct, thus marking > the patch as RFC. My guess is that typec_match_altmode() is the real culprit. We can't rely on the partner mode index number when identifying the port alt mode. Douglas, can you test the attached hack instead of this patch? thanks, -- heikki --82I3+IH0IqGh5yIs Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="tcpm_hack.diff" diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index ec525811a9eb..033dc097ba83 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -1067,12 +1067,11 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt, modep = &port->mode_data; - adev = typec_match_altmode(port->port_altmode, ALTMODE_DISCOVERY_MAX, - PD_VDO_VID(p[0]), PD_VDO_OPOS(p[0])); - pdev = typec_match_altmode(port->partner_altmode, ALTMODE_DISCOVERY_MAX, PD_VDO_VID(p[0]), PD_VDO_OPOS(p[0])); + adev = (void *)typec_altmode_get_partner(pdev); + switch (cmd_type) { case CMDT_INIT: switch (cmd) { --82I3+IH0IqGh5yIs--