Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2898782pxj; Mon, 17 May 2021 12:30:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8ybnlSJycOYWyMqx5Z/jEhWcJ7W+N1MrJOOvsLTfrhgMhnP7gbO4SctsxYoIJ33n1JjgP X-Received: by 2002:a17:906:bb0e:: with SMTP id jz14mr1524623ejb.285.1621279857021; Mon, 17 May 2021 12:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621279857; cv=none; d=google.com; s=arc-20160816; b=mN/k8gyZ+Y7tPnWzGp1tSomhjWYxdt6ffd2j5743ZrD95J1NwuGERAR7nEIkGyQQYs pA0vIV5LA5BcEN2GQAOTdBmahMActgrBtNUspAZOBskprS5+IL0qV7FF2IqDF49NaPE8 1hPwI62is0sLWYtG7+PRi2cJo31VeecwoQw7MUwqsTwufchKbl/ok1dcpkjS1xs6tHgQ E7Ry5n6T32XfuTjw7f3iKBDUuCb1OsE9r/irO0VovvOCsiJAiYjD+Ohz/1aLpUJsvKhA T6+UvDe4FepBQKxfILDVXglZPX8YteSs9uM65l8YSyYm4SgTbiJ9ywJaEAOrmt8iYBCI pDVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=otmFCl6tz/Mf01ND7Pw7g8W/n12KOu7HMzV8vb27prM=; b=PZVJONUuw56gX4dyOkbKgxKgLGyredgdqkmZZQk3IlD8gnwQnaNfG1boZq4hMKXfd6 aSKBIzd3FfZ3qpIahUxlDLmuCRjb6t3hxRhQFgc9vO6Ml8OcblpSikQyRMvIvpEvntC7 La2j466mtiZMlfbEd1dWmN+2YgtG8J2ElhFwIk4mOHcahVk9pijcJ4Rjb252l6KGRIGO G86pGFJztHn0Y7LAlt2Id+02HF8WdPwrasiuUQr8P9rnGBRnB6egAEd0AlMyjA9zxUqu nQw3Lb6OQeqhZcQkDgejEzC5D3uw08P9q3UMjXIUJc8TDwMNil+Iqya6Y3B4+9xo0kBb nmpA== ARC-Authentication-Results: i=1; mx.google.com; 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 cm11si11882328edb.424.2021.05.17.12.30.33; Mon, 17 May 2021 12:30:57 -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; 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 S235308AbhEQNom (ORCPT + 99 others); Mon, 17 May 2021 09:44:42 -0400 Received: from mx2.suse.de ([195.135.220.15]:50568 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235085AbhEQNol (ORCPT ); Mon, 17 May 2021 09:44:41 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A9A76AEB6; Mon, 17 May 2021 13:43:24 +0000 (UTC) Date: Mon, 17 May 2021 15:43:24 +0200 Message-ID: From: Takashi Iwai To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Jaroslav Kysela , Takashi Iwai , Greg Kroah-Hartman , Oliver Neukum , Vasily Khoruzhick , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] sound: line6: Fix race condition in line6_probe In-Reply-To: <20210517132725.GA50495@hyeyoo> References: <20210517132725.GA50495@hyeyoo> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 May 2021 15:27:25 +0200, Hyeonggon Yoo wrote: > > syzbot reported general protection fault in midibuf_is_full. > the cause is linemidi pointer in struct usb_line6 isn't properly > initialized. > > the pointer isn't initialized because there is race condition > in line6_probe. it calls line6_init_cap_control first, which submits urb. > and then it initializes it's data using private_init function. > > so it's possible line6_data_received is called before it's > data isn't initialized. > > Link: https://lkml.org/lkml/2021/5/17/543 > Reported-by: syzbot+0d2b3feb0a2887862e06@syzkallerlkml..appspotmail.com > Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Thanks for the patch! It's an issue I'm tracking now, too, and you submitted quicker. But, unfortunately, this swap does seem yet another potential race between the private_init call and line6_init_cap_control(). The actually needed initialization is line6_init_mid() call, and this can be fixed by moving to the appropriate place instead of inside each private_init callback. So my current fix is like below. thanks, Takashi --- diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index a030dd65eb28..9602929b7de9 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -699,6 +699,10 @@ static int line6_init_cap_control(struct usb_line6 *line6) 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) diff --git a/sound/usb/line6/pod.c b/sound/usb/line6/pod.c index cd44cb5f1310..16e644330c4d 100644 --- a/sound/usb/line6/pod.c +++ b/sound/usb/line6/pod.c @@ -376,11 +376,6 @@ static int pod_init(struct usb_line6 *line6, 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) diff --git a/sound/usb/line6/variax.c b/sound/usb/line6/variax.c index ed158f04de80..1376fc405c7f 100644 --- a/sound/usb/line6/variax.c +++ b/sound/usb/line6/variax.c @@ -172,11 +172,6 @@ static int variax_init(struct usb_line6 *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: */ schedule_delayed_work(&line6->startup_work, msecs_to_jiffies(VARIAX_STARTUP_DELAY1));