Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4882367pjb; Mon, 27 Jul 2020 07:31:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYAW/SrzCdVXn3mdbCTc07V49CUyZ9UyoCQdf7oIQod2U10QAxpC7LpiUK/qadoWRp6qtz X-Received: by 2002:a05:6402:7d5:: with SMTP id u21mr4822295edy.235.1595860276734; Mon, 27 Jul 2020 07:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860276; cv=none; d=google.com; s=arc-20160816; b=LcrqlXxxfomwK5rl+6cUZpCPE8qW2X7m22ZzrGFq1+I007SToVA/8M9M/776X10UBc g5VZSTIqfeU7jAAle2gmKMWkcoikjhLcyyGT/82mIvUoYCXcq1qhkD6GonD4lAdCQclQ x8OUqpv7d+WOPxu8fRC3b7HZ+c+GMt4+xAbSQw80+//8tfnoTu20YkvNX1MBuxxptl+U lFEyzhNOy8fP2QJgLYHvGEh7JkaqNb50CP7o8h0Ot5pX3GPQwO7cuhEwtvLB/uVBX+HZ ca2K7pJxPcJEf2vYcmHtGfoDxf71KN2qbVhHhwVp6xXfb2dpeK+9RPNZIIEeyatQ1TDE T6Sw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=d3wtFGWYJx8WsJMa7ho4gSBVsdzDeNE9xxPqOjPYa7k=; b=zWfSZgo2n9A+UHLXgVCr4a5/l8rj43EKQ+E3cu98Z70Du/lcPj/kOlNY7i7J1o4pnN 0gzHSbbcVvIUEUBtCcg+OxFJBoCQs8SoiG4Tcf3J+OedTAEKRt4jHvRHagDAQPGa8l3u 0nfvpXM9UsXVmdl2UjC+TN2iJ7xV76pcL2LN7/K7IyhT6pVnLbe28CUEgujhZz6nsDMT vYSgU75FCw5UZ/BIED1KF16A0wEiS5wADIsElxpYp82O57Elney6wi1VdAzKaQcJzWVZ 8BsV1VDR42YMRV5qqEXVLKLawYpGLn8omx0S6679vgVutRm75isjXTA4zzOyKj91ioTt E0iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="s1pa5/nv"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m2si2801117edl.543.2020.07.27.07.30.53; Mon, 27 Jul 2020 07:31:16 -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="s1pa5/nv"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732378AbgG0O3n (ORCPT + 99 others); Mon, 27 Jul 2020 10:29:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:52168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732009AbgG0OXF (ORCPT ); Mon, 27 Jul 2020 10:23:05 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A0C552070A; Mon, 27 Jul 2020 14:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859785; bh=CNA2UcGDHuCk9lpCPB6VSEaq6G3lroCk8+yxTtXAEhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s1pa5/nvBoIR4ZFwjh5B1Az1PQRbAM/kOAXxBnzs7myPrXHTn7DhL1nMq8izyjfPd TOam1KQm4mwyUD4dqEOYSu0iiR8jdJAytIOH0qmsZ112oJqnITpo7RCDvhAC2A9Jas 7aPL9W1nbcJC8nmoF/whm5V97ukdw+lrnVW9Vg3I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rodrigo Rivas Costa , Siarhei Vishniakou , Jiri Kosina , Sasha Levin Subject: [PATCH 5.7 104/179] HID: steam: fixes race in handling device list. Date: Mon, 27 Jul 2020 16:04:39 +0200 Message-Id: <20200727134937.717489856@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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