Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2644222pxj; Mon, 14 Jun 2021 03:53:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvDnAfuTzoKMwZuIhLNy20kZgSxNMQMWrJ3ENfo+IySQvbMrdbj0/bZ7+DP1TyRwiZSXj0 X-Received: by 2002:a05:6402:1713:: with SMTP id y19mr16192351edu.346.1623668023182; Mon, 14 Jun 2021 03:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623668023; cv=none; d=google.com; s=arc-20160816; b=lgxwMs9XAKNwUIunlLXRT8d63urixPB1Qvb6xPCtBizS+4NEIxgDhRW8OpHlBAlEPj kq/Oh5NeA3GlJESGt3vRy8sz0UrIrpufIyv5NY4uEnAaCymQ1+wSI5Rxd8jZZ/JFV0uJ 2pchcB8H8eiD2wfRbAgoZ8jZtF5mkptQl4UcIqYNqwBpKzW/J+gjG3MWxPEy/2PNfs3D rLE7I0zSU2kkZ3oPK+3i2SojDK3O+WXJgUjlrZwt8RfxJAG8sZdVSv2tquLrcunNKIDe 4sUFFdqoRPEjlNoFNecXbpiSo9TBN4KgGVG/y5jTFTvwbU3qne86MKHyhJYQGPpb7LzP lfCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B3eRUVXRtxvvuD2hiCN60Bxbb+88Ebnwq4lKqHJKFvk=; b=DoJxX2MbOov4VitBrpk+b+pQOZ4qb/jKNMQg2Z7bRgdw7iFfsBFgj3tMvtrslVOvbT fwVSt1SjV5m0MpdUNj4AlwSJLcnhK83a4qCPKrvXSfiyI/+sEGWIxy8Z1cZ98G5Tjyo2 cibXOQcfznOJi3f/XV9XYdGZEyHBUB+TmKbINag+UpQ3IjbddXmOpUg0QggSj8tuPFvK L/X8GecWQbibeCrcR1OpXWtasyBjHsBusBzkQNQQ0ItfuSUJVA78LrNRokLQBVW2L2WO NJ1E7ee5Tvp0MC7yLyJeerOM+CYb29cUjT/CsEtNsltYA2LPzf+aXbF5BBnihGwRohTI nwuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XymKILlM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd1si8829746ejb.258.2021.06.14.03.53.20; Mon, 14 Jun 2021 03:53:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XymKILlM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233690AbhFNKxu (ORCPT + 99 others); Mon, 14 Jun 2021 06:53:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:50672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233748AbhFNKqk (ORCPT ); Mon, 14 Jun 2021 06:46:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3D11E61451; Mon, 14 Jun 2021 10:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667024; bh=iOjI+OXJcGrifEBSoUpsLsFOs+/ZJtgNDKfWcJKMzR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XymKILlMNDM0cDkoGSozzJG0qmSsM3Ojlw82nVfLkG6CUDQ1SRVImdbCQgCTeDh9q r6BlKvFWleoceTc2MUYiMnbrZAr5V09S4TB5MMrlY2I6nZDwa3ErGGFuf17r+AICzI 3zzUzFdXmoY+PuZJ/67Co/W8cuM14RbOEphNWWBI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heikki Krogerus , Mayank Rana , Jack Pham Subject: [PATCH 4.19 40/67] usb: typec: ucsi: Clear PPM capability data in ucsi_init() error path Date: Mon, 14 Jun 2021 12:27:23 +0200 Message-Id: <20210614102645.136124651@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102643.797691914@linuxfoundation.org> References: <20210614102643.797691914@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mayank Rana commit f247f0a82a4f8c3bfed178d8fd9e069d1424ee4e upstream. If ucsi_init() fails for some reason (e.g. ucsi_register_port() fails or general communication failure to the PPM), particularly at any point after the GET_CAPABILITY command had been issued, this results in unwinding the initialization and returning an error. However the ucsi structure's ucsi_capability member retains its current value, including likely a non-zero num_connectors. And because ucsi_init() itself is done in a workqueue a UCSI interface driver will be unaware that it failed and may think the ucsi_register() call was completely successful. Later, if ucsi_unregister() is called, due to this stale ucsi->cap value it would try to access the items in the ucsi->connector array which might not be in a proper state or not even allocated at all and results in NULL or invalid pointer dereference. Fix this by clearing the ucsi->cap value to 0 during the error path of ucsi_init() in order to prevent a later ucsi_unregister() from entering the connector cleanup loop. Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface") Cc: stable@vger.kernel.org Acked-by: Heikki Krogerus Signed-off-by: Mayank Rana Signed-off-by: Jack Pham Link: https://lore.kernel.org/r/20210609073535.5094-1-jackp@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/ucsi/ucsi.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -735,6 +735,7 @@ err_unregister: } err_reset: + memset(&ucsi->cap, 0, sizeof(ucsi->cap)); ucsi_reset_ppm(ucsi); err: mutex_unlock(&ucsi->ppm_lock);