Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4493875img; Tue, 26 Mar 2019 10:26:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyv7lt9WdcsaPHloyLWWeFfN8RnG4RzcEetEMKJ+PafaCGcAxK87DYcUzmJV0sRVq0LqUg0 X-Received: by 2002:a17:902:6b47:: with SMTP id g7mr33242464plt.100.1553621164550; Tue, 26 Mar 2019 10:26:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553621164; cv=none; d=google.com; s=arc-20160816; b=JQ4S+uiLi2GMGPlo4rukrCTgLsXKoTX0x1hcC9nKmIamJJMOn4nOILEg4LBNi+/sOF DO2UTyDZqSKH69YKiv6hj+fKdJnEEVa9Hd06d4hN/GNeYP1Tujzqe4XOLMxwLjVQL0rJ ujnXH3bVTalwGqB8/2G6HCbrFYnj7E5aJm3m5a5cj9SqNz2HDBbYHB1d6YgnRLhNRM90 nSpb3ADd0E00kSHq/cplqhCH1DOAdpBoJGAItxJiGkjh5V0185UqMBsH9MOEqD/+9vt4 XA1CnswRpKVUn7rSmkAW6eqikKcncj6USdza9bozyyYwDwJOmxGkCSe7Tu2XHAYSHaFS /I/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=l19F8lJd5IdArfySDoFtGyFlcftIi55XoMtqQbgctkY=; b=fPcAvV6AxDMgImYB3pM7iK5VvhpuR1lr8vJZ6a7s3fJrLjOR+XMXnrskhDsubZixR+ aqy11rWLBv9YZR7FajQ5Pd7ZeLiW6zRCQXvdrKUF/bYoZiSOQKKq963Z8jIJlwSBaUOe FvG+DwRaUrvHdR8UnuAV/+iaVers7eVMs2xZhESNZjcXRFGRUepUI8hYtVeFWngoj5SS Xf7pPL+F8lOD0C9adMi6DJYXkS7lp+9V98wJC/dCtVIX4JaZ9BYA9gI8r7STZO4XiMwy Lnctg0cl0Mxa4880T7hdx34Gn6BVh5x6L6nF3YYVhaMVErX//qQkbmluqzcRLtCU4Qpa k5OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Ddjgq39Y; 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 j8si15950613pgq.542.2019.03.26.10.25.48; Tue, 26 Mar 2019 10:26:04 -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=fail header.i=@gmail.com header.s=20161025 header.b=Ddjgq39Y; 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 S1732034AbfCZRXn (ORCPT + 99 others); Tue, 26 Mar 2019 13:23:43 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38278 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726278AbfCZRXn (ORCPT ); Tue, 26 Mar 2019 13:23:43 -0400 Received: by mail-pl1-f195.google.com with SMTP id g37so1940513plb.5 for ; Tue, 26 Mar 2019 10:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=l19F8lJd5IdArfySDoFtGyFlcftIi55XoMtqQbgctkY=; b=Ddjgq39Yp+OUaC/VdMUmib8F9+AVVPOeJWFH/q0LHlRbcU3bEVtW4HgJ6dCmMUSyRN 8QhEexMOLLjL1VHeT4Nyw2fOWBrDs8HNWf12octbjiSI6MdUAUODcmgBkD3Xm7w0GxdR Kfiugswwo3myJ2tGRvwr/T0cDYE1zMjwxVzI7PIJWNyP15dg2Cvo7hjgTaVvc9ZjoZ+9 7vwe3VgwMmhiuJrT67wsnh56w1w2dx+Sip0kki3aDl5OR0VzH1u9b+hxypsrTK3/ix/7 hRDDbiRpVEsSkN4/fnnsAHvO6hxYip6Jqay5RPgevM3hAnJ7bF5RTUmF9Syd8RDPirAe ZhSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=l19F8lJd5IdArfySDoFtGyFlcftIi55XoMtqQbgctkY=; b=BB9huz8o43/Xp8jVV/VFV3I2ZFHHmiwHolzq/rkkf5VZ2aY02wp8WiPImUml+3wLQ7 +LUdihsvkEtPFnNd5gPgFN4SATgHPcS402ftnr2vYH9JouWTydyQed+Mg1zCBRxbJaF2 +svhy51Yh23IMtRB2qjrLS3bhdHSHJOTHhRyiRFEuIFTiroY/cY/o8/p4U8QGdx02OI+ a0DqigT6phdGeUfx0XwCTT3tB0A7ua0Wf/6a67icZlHbZJBlUQa6FZMS1M7QFcRCYY0X 0dQpyA9nD/jyzh8pzErhG2obDJcolF2Wij+Z0uIsH/aLHvHo/VbYgMHvilnAF7guh4uU l55Q== X-Gm-Message-State: APjAAAWqacd3C6sjkSGcKaQ64QGl4Pz9E7oexBUDHZQpCerobiOMDvOy leuVVP0FXQWPiHRbxf1+1X4= X-Received: by 2002:a17:902:142:: with SMTP id 60mr32336145plb.191.1553621022777; Tue, 26 Mar 2019 10:23:42 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id v12sm4310670pfe.148.2019.03.26.10.23.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 10:23:41 -0700 (PDT) From: Guenter Roeck To: Mark Brown Cc: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Guenter Roeck , Curtis Malainey Subject: [PATCH] ASoC: core: Fix use-after-free after deferred card registration Date: Tue, 26 Mar 2019 10:23:38 -0700 Message-Id: <1553621018-8944-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If snd_soc_register_card() fails because one of its links fails to instantiate with -EPROBE_DEFER, and the to-be-registered link is a legacy link, a subsequent retry will trigger a use-after-free and quite often a system crash. Example: byt-max98090 byt-max98090: ASoC: failed to init link Baytrail Audio byt-max98090 byt-max98090: snd_soc_register_card failed -517 .... BUG: KASAN: use-after-free in snd_soc_init_platform+0x233/0x312 Read of size 8 at addr ffff888067c43070 by task kworker/1:1/23 snd_soc_init_platform() allocates memory attached to the card device. This memory is released when the card device is released. However, the pointer to the memory (dai_link->platforms) is only cleared from soc_cleanup_platform(), which is called from soc_cleanup_card_resources(), but not if snd_soc_register_card() fails early. Add the missing call to soc_cleanup_platform() in the error handling code of snd_soc_register_card() to fix the problem. Fixes: 78a24e10cd94 ("ASoC: soc-core: clear platform pointers on error") Cc: Curtis Malainey Signed-off-by: Guenter Roeck --- sound/soc/soc-core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 93d316d5bf8e..6bf9884d0863 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2799,6 +2799,7 @@ int snd_soc_register_card(struct snd_soc_card *card) if (ret) { dev_err(card->dev, "ASoC: failed to init link %s\n", link->name); + soc_cleanup_platform(card); mutex_unlock(&client_mutex); return ret; } -- 2.7.4