Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp839208yba; Wed, 24 Apr 2019 10:25:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGnWC4V8Pc8KItEXjviBjs2dA/Atx/WclRQTIiUa6Adm6wIB6XsZEWaxKI5RHx5Q+j0ko5 X-Received: by 2002:a65:65c9:: with SMTP id y9mr31821581pgv.47.1556126723608; Wed, 24 Apr 2019 10:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556126723; cv=none; d=google.com; s=arc-20160816; b=UPSYG5LrBPk++Rv+GQe0QdZtV0C7vtlGmg6Ko/MHfN6v62kmBbuJBMBXBtuFWicmSl CMu3w1zqWl8cO8kJnylx9OBA9y2UPc18JlB4u3v6pMH5z21XERj/ztp8+3MLsav685xw L+/V6a/FrsyRFxHC1DBZZ2Jm7O6ZNBmARV24rOBiAEX7xx2U2Sl53HYC7/0jJM+xY5Gs Kw0UJdnUCOeifhmlhzYdYFw63tHpQ5sOle8D78uRaqWxzXjSv/bH+H83lsMsiuDAdoDF tNtZPR2oMytzBwybg4VStev80bnk+wRzKuVAl5ucKxMASbkgRMVc97O4dfXoVCBsevJ9 JMpA== 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=UCVVtxAIQiNJvMgDoGHI4+MFOapuhxsUBEm9W7ftaM8=; b=ECrX4R+tOu7g+GO0nRPLaobUrCx1cXkMm83kS6JJAduufyFv2/JSp3QlAk9ctJbFdW PTjG2fEGJCwxRKYUMN2VzFJW6WPvppcD/BsMaCVKHjs9Mvck3wqJDBoXNdO+Tvi0h1y0 McxnXFl9hsKUY0K5Dpuv8doi6hjTy326jboqvZUulxVZsmgQl8cV4sSnlfMyo8a4Dvcd BuGWGveYeLrb5PC7NSypwGUT8pQg2TpxoSEWRop9YNiR58ay9x+n0kHpC1FjhebXxTBs E/jFZuFedj82h6ihDSfAQWUGu7zQVaNL8wYckEBeKNrlr7JvvSNOwCrZ29UM0BzuKRgF luMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gpmhQ7lW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 74si18234553pgb.203.2019.04.24.10.25.08; Wed, 24 Apr 2019 10:25:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gpmhQ7lW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389725AbfDXRXf (ORCPT + 99 others); Wed, 24 Apr 2019 13:23:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:49266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389327AbfDXRXc (ORCPT ); Wed, 24 Apr 2019 13:23:32 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (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 1502E2190C; Wed, 24 Apr 2019 17:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126611; bh=YoMf8MXUdVRAhakUKjCUZERg4lak23Jtcb5RKtOF4HM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gpmhQ7lWpef5IVguqq9BlXFQn3a8uSUPMM4wC5acmevKMSxrSVzordefBj+F5Zstl GUFwWBWRSdbk3mr/TAZ0oquLR1OxI4nNOPLZFqyMhgjyhhnpB70qNfvpPgumJJgZkr zet4L8/N5rdVpo2NoMMCALl5Rw1M1f0XwxmKnm3Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+48df349490c36f9f54ab@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 4.4 168/168] ALSA: info: Fix racy addition/deletion of nodes Date: Wed, 24 Apr 2019 19:10:12 +0200 Message-Id: <20190424170933.179251406@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170923.452349382@linuxfoundation.org> References: <20190424170923.452349382@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: Takashi Iwai commit 8c2f870890fd28e023b0fcf49dcee333f2c8bad7 upstream. The ALSA proc helper manages the child nodes in a linked list, but its addition and deletion is done without any lock. This leads to a corruption if they are operated concurrently. Usually this isn't a problem because the proc entries are added sequentially in the driver probe procedure itself. But the card registrations are done often asynchronously, and the crash could be actually reproduced with syzkaller. This patch papers over it by protecting the link addition and deletion with the parent's mutex. There is "access" mutex that is used for the file access, and this can be reused for this purpose as well. Reported-by: syzbot+48df349490c36f9f54ab@syzkaller.appspotmail.com Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/info.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/sound/core/info.c +++ b/sound/core/info.c @@ -724,8 +724,11 @@ snd_info_create_entry(const char *name, INIT_LIST_HEAD(&entry->children); INIT_LIST_HEAD(&entry->list); entry->parent = parent; - if (parent) + if (parent) { + mutex_lock(&parent->access); list_add_tail(&entry->list, &parent->children); + mutex_unlock(&parent->access); + } return entry; } @@ -809,7 +812,12 @@ void snd_info_free_entry(struct snd_info list_for_each_entry_safe(p, n, &entry->children, list) snd_info_free_entry(p); - list_del(&entry->list); + p = entry->parent; + if (p) { + mutex_lock(&p->access); + list_del(&entry->list); + mutex_unlock(&p->access); + } kfree(entry->name); if (entry->private_free) entry->private_free(entry);