Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3529249pxj; Mon, 24 May 2021 08:44:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJkHaso+AfpTMOuePHvfkfjTCIB9RDrBcv+yevlQpEXxqYjCBYRwVzYghk+UHuWWvG4LgP X-Received: by 2002:a6b:5015:: with SMTP id e21mr16673322iob.104.1621871077922; Mon, 24 May 2021 08:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621871077; cv=none; d=google.com; s=arc-20160816; b=N550zbaVOzg+NXvX+ySTSOiDlxVLPfitO2XJLSio6+uL6Cr7f6tkUGFPx6pLUYX0Hw 0QslN9/WuilZsw3RbjHk5DMlxGH3ATEoqW6C1EHz0bi4qyb4tePxjuef6SjXQbym3LLy Z/2Ei6rxp65CiMirt8FFJKcFYw4PzMe5GUA00x61TmA4aZZOn8mxYfBdBf00kwYfc3u1 do4attl484NofXus5aXsUbxlv3soO3iasmuJYnxMVXc5IozZ+Y6GbelliJNZ+KUkDIVQ Gida6YttjqyHtTAna1EuTrhDXXxeK5ILtdlO2L77xerVE80FWioo4DKolRJSs+vLhp/k 0mpA== 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=526yozc9vVL1L1Wec48OB2b8ZjCJkh+3+qFEEq1EYlk=; b=NFQn8F8Ab1oNWQbQVnPiXl6s54dHRDougmkYKIMg1H1OIrlJEcbET1ltLCWZy8CLYe IjIAzw8svty1o372IbXS3HmW/V2jOD48K3kgH4PQyXN80AGoZNCpMeqO/CWWuIkdfXLu myuGHiSodg6Ub7XPKXElSD/enKZKaH9bPjYc/CA990gJCL0id7CK6cPSufKcx0T94O7p yiGp8ZI2ML2+U/I4wciAjHzqHFr8uI/CYqOlqnfl/+y8vaBPb9x4R/K1kbJEacR4WAgQ nJiw3Hz0bAC9vs8JCsZ4tCY9n9EUKSi5cJopq5O37WJPLGnezmIFHQj7B0hu+HR88YGq /swg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="k+FY/4UM"; 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 a2si15042336ilh.91.2021.05.24.08.44.25; Mon, 24 May 2021 08:44:37 -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="k+FY/4UM"; 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 S234679AbhEXPoc (ORCPT + 99 others); Mon, 24 May 2021 11:44:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:58368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233009AbhEXPk2 (ORCPT ); Mon, 24 May 2021 11:40:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B725D61423; Mon, 24 May 2021 15:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870458; bh=GiFo+j/eaoh4G+oxXE8pCQfSHUeJLxULqf52JcMWLy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k+FY/4UMGGKjIo8VBTq6ydaqBp+MsYgy5Bg+oK9gvYvjyeM0ExRg62iI4SuijsRha 0PvkC8c+itz4YRB/aLqlvDTxeJmB7wz/iJnbWga2AeQOMtBgcgSkR+s03/+YV8XM42 2WrPiwRYcMzPgnYEp8bg7rHHWpf346ZRKOb2tB40= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hyeonggon Yoo <42.hyeyoo@gmail.com>, Takashi Iwai Subject: [PATCH 4.14 06/37] ALSA: line6: Fix racy initialization of LINE6 MIDI Date: Mon, 24 May 2021 17:25:10 +0200 Message-Id: <20210524152324.408860425@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.199089755@linuxfoundation.org> References: <20210524152324.199089755@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: Takashi Iwai commit 05ca447630334c323c9e2b788b61133ab75d60d3 upstream. The initialization of MIDI devices that are found on some LINE6 drivers are currently done in a racy way; namely, the MIDI buffer instance is allocated and initialized in each private_init callback while the communication with the interface is already started via line6_init_cap_control() call before that point. This may lead to Oops in line6_data_received() when a spurious event is received, as reported by syzkaller. This patch moves the MIDI initialization to line6_init_cap_control() as well instead of the too-lately-called private_init for avoiding the race. Also this reduces slightly more lines, so it's a win-win change. Reported-by: syzbot+0d2b3feb0a2887862e06@syzkallerlkml..appspotmail.com Link: https://lore.kernel.org/r/000000000000a4be9405c28520de@google.com Link: https://lore.kernel.org/r/20210517132725.GA50495@hyeyoo Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Link: https://lore.kernel.org/r/20210518083939.1927-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/usb/line6/driver.c | 4 ++++ sound/usb/line6/pod.c | 5 ----- sound/usb/line6/variax.c | 6 ------ 3 files changed, 4 insertions(+), 11 deletions(-) --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -698,6 +698,10 @@ static int line6_init_cap_control(struct line6->buffer_message = kmalloc(LINE6_MIDI_MESSAGE_MAXLEN, GFP_KERNEL); if (!line6->buffer_message) return -ENOMEM; + + ret = line6_init_midi(line6); + if (ret < 0) + return ret; } else { ret = line6_hwdep_init(line6); if (ret < 0) --- a/sound/usb/line6/pod.c +++ b/sound/usb/line6/pod.c @@ -421,11 +421,6 @@ static int pod_init(struct usb_line6 *li if (err < 0) return err; - /* initialize MIDI subsystem: */ - err = line6_init_midi(line6); - if (err < 0) - return err; - /* initialize PCM subsystem: */ err = line6_init_pcm(line6, &pod_pcm_properties); if (err < 0) --- a/sound/usb/line6/variax.c +++ b/sound/usb/line6/variax.c @@ -217,7 +217,6 @@ static int variax_init(struct usb_line6 const struct usb_device_id *id) { struct usb_line6_variax *variax = (struct usb_line6_variax *) line6; - int err; line6->process_message = line6_variax_process_message; line6->disconnect = line6_variax_disconnect; @@ -233,11 +232,6 @@ static int variax_init(struct usb_line6 if (variax->buffer_activate == NULL) return -ENOMEM; - /* initialize MIDI subsystem: */ - err = line6_init_midi(&variax->line6); - if (err < 0) - return err; - /* initiate startup procedure: */ variax_startup1(variax); return 0;