Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp212465ybh; Mon, 20 Jul 2020 14:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcFsXe0KxQMzspE1VkPGJKkzva7NDr+NyssNpolifOMBzvrfK9uelfGrOEQ/YQ9PiEZVOS X-Received: by 2002:a17:906:b24d:: with SMTP id ce13mr23659057ejb.546.1595281459057; Mon, 20 Jul 2020 14:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595281459; cv=none; d=google.com; s=arc-20160816; b=sG0Xu4IBZt2GAtnhvsfzitr8Nxdl9rtnJLwLHbCIXu8YYcmBluMRYa1zSchSHT4IpM hnXmvBBjPtcWtgy+CV777i2VKOU+AwTXfHjqs0THpnpV+kAMOqeCkPWOUxnASxZ0q1a/ 5PS38WdhsqQZBSK7LXeT31NAoxUHcgZZ9YcS5nhHySF6tmbQs09+FPehVNBsDT7fWmea xBgeYf7t128bZEgQZgWl1yu+1ccUcB7Zgq5JI2mvOs03FM3DSvqpWP2fzkgDv5GII7kR xfN75GXm/IlNezQ2wzzbjr2CzCj86156/NV0utdZEzMqGTU8j4ryJF7QsGb6oMVSixNy YDsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d3wtFGWYJx8WsJMa7ho4gSBVsdzDeNE9xxPqOjPYa7k=; b=eZYD4Q0PIINT5X8GMRof79AS820VF1BYly2h+JQshgB8sKRxSG6vYQ0B13vvP6iaT9 9usCVXmLVO3k6aY1I91jeoz6TPJI0izxRdCVV1FDsBlfeDQchiRYASSzLgi/oPPIEWd1 Az47AzloD4bI7QDHzghXYbk+ytzybYoslgUuy/zJ8+y8YUj9sTDaiJPsamgf+8l8baMN SF8CIpKD37JVkl8/wrKpbzQyw2yxAl4j3iuB+6PKxVuStRuKuXelx/MSSRsU50mqLNse RKWgqDffDpgeIkE5n0ljujzGkWVV8SskDIxDFoV40UN4NE48x59QNsjkR2+93QplV42C S64g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="jcv/UteG"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si11304986edz.108.2020.07.20.14.43.56; Mon, 20 Jul 2020 14:44:19 -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=@kernel.org header.s=default header.b="jcv/UteG"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728845AbgGTVmc (ORCPT + 99 others); Mon, 20 Jul 2020 17:42:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:57852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728288AbgGTViz (ORCPT ); Mon, 20 Jul 2020 17:38:55 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 63FDB22C7B; Mon, 20 Jul 2020 21:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595281135; bh=CNA2UcGDHuCk9lpCPB6VSEaq6G3lroCk8+yxTtXAEhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jcv/UteGUAFK4F2qWqVUFNpr9YAG45FdSBza1nHWzT0vdrLQl7hqe2yqLqXw58Nhw dR62/Ce24NdKSRWq+BpbJOUxgcB79u82UJ2Hl835XA70hEswyHnjraAvwX3rxzXEHQ gVuy47EZ6bULqv97zD+J+Wo8ne0miS42XjTINWNE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rodrigo Rivas Costa , Siarhei Vishniakou , Jiri Kosina , Sasha Levin , linux-input@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 03/19] HID: steam: fixes race in handling device list. Date: Mon, 20 Jul 2020 17:38:34 -0400 Message-Id: <20200720213851.407715-3-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200720213851.407715-1-sashal@kernel.org> References: <20200720213851.407715-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rodrigo Rivas Costa [ Upstream commit 2d3f53a80e4eed078669853a178ed96d88f74143 ] Using uhid and KASAN this driver crashed because it was getting several connection events where it only expected one. Then the device was added several times to the static device list and it got corrupted. This patch checks if the device is already in the list before adding it. Signed-off-by: Rodrigo Rivas Costa Tested-by: Siarhei Vishniakou Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-steam.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index 6286204d4c560..a3b151b29bd71 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -526,7 +526,8 @@ static int steam_register(struct steam_device *steam) steam_battery_register(steam); mutex_lock(&steam_devices_lock); - list_add(&steam->list, &steam_devices); + if (list_empty(&steam->list)) + list_add(&steam->list, &steam_devices); mutex_unlock(&steam_devices_lock); } @@ -552,7 +553,7 @@ static void steam_unregister(struct steam_device *steam) hid_info(steam->hdev, "Steam Controller '%s' disconnected", steam->serial_no); mutex_lock(&steam_devices_lock); - list_del(&steam->list); + list_del_init(&steam->list); mutex_unlock(&steam_devices_lock); steam->serial_no[0] = 0; } @@ -738,6 +739,7 @@ static int steam_probe(struct hid_device *hdev, mutex_init(&steam->mutex); steam->quirks = id->driver_data; INIT_WORK(&steam->work_connect, steam_work_connect_cb); + INIT_LIST_HEAD(&steam->list); steam->client_hdev = steam_create_client_hid(hdev); if (IS_ERR(steam->client_hdev)) { -- 2.25.1