Received: by 10.192.165.148 with SMTP id m20csp2429054imm; Sun, 22 Apr 2018 06:59:32 -0700 (PDT) X-Google-Smtp-Source: AIpwx48/ncBK2hKCE7Qqod5KkxV/sPvYaE7Yt/hn9X/hvbOX3mDK2RDAVhoZgRN7HHcHmCKdvdHa X-Received: by 10.98.155.87 with SMTP id r84mr12061379pfd.109.1524405572190; Sun, 22 Apr 2018 06:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524405572; cv=none; d=google.com; s=arc-20160816; b=zXPybGbmnE1w4eRSfO5wy3Ju7CMBaiEYUf0356JzBmJ+mBTTKlYBTC1GVdgG0qbYAw WhGeCcNKsmIfIIU3vxNzqX+FrDMT6wWdAvdBWFcGLJ084ZuJ4K79v18p8t2pQyDtdRFO uI6t2leZyjPacIuy6l22CYMGEKdsvi9Qy65sO8Y2iFpRZrUk98eQlqErEwX3+o0G0sb6 Our9ZIwbSeacabrOpMRhrt+Fr3vUWTETh/FczJtaTHb2NjEsAESZpR0mayAFkN22+8VS A0XuGSOF8duVn4yreMX6CzpuLDdYlBQwwBqQ5HIBjd4qmUddpzWo5ujRb1sHiFOvgjqr cDhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=DCOJNu7Pjq1adpFZn2KVgv34ZYj7blhekA491N/TXL8=; b=UsoE+JvP7L61l9mA4j0OIrPJ0KiEM4hGXD6hagxjI/xCMncrxMmq5r+xX70xcZ5eVn YFpn/POwe/E3RiRJtal1/ORkQkT8Ohs2JxOL7b2TzIirW6QDp4Xop2yIX1o8StwnOdLq P5mnJQ4Y+/8X2l6ToBcBDcpd0t7HL91TbaiMMcZ2a+7+0gksAfZR9LxEtk9RPrxNcTJ3 Q0/da+rdZfNLJH3dHpbmJvpQwDMW/4HUVicGdduRiclad+r2x/n50bcWU38e0VjO7/HG yTP+jeYz4sIpd02xXoQiHB2gq4dGvMZY4SEnsYX1a3ebzV4+4Gi/mcftiCH1s5JCewNX 7Y8w== ARC-Authentication-Results: i=1; mx.google.com; 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 k186si7916092pga.676.2018.04.22.06.59.18; Sun, 22 Apr 2018 06:59:32 -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; 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 S1753720AbeDVN5v (ORCPT + 99 others); Sun, 22 Apr 2018 09:57:51 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45874 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753672AbeDVN5m (ORCPT ); Sun, 22 Apr 2018 09:57:42 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6C4489CE; Sun, 22 Apr 2018 13:57:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liam Girdwood , Mark Brown Subject: [PATCH 4.16 074/196] ASoC: topology: Fix kcontrol name string handling Date: Sun, 22 Apr 2018 15:51:34 +0200 Message-Id: <20180422135108.065623981@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liam Girdwood commit 267e2c6fd7ca3d4076d20f9d52d49dc91addfe9d upstream. Fix the topology kcontrol string handling so that string pointer references are strdup()ed instead of being copied. This fixes issues with kcontrol templates on the stack or ones that are freed. Remember and free the strings too when topology is unloaded. Signed-off-by: Liam Girdwood Signed-off-by: Mark Brown Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- sound/soc/soc-topology.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -523,6 +523,7 @@ static void remove_widget(struct snd_soc kfree(se->dobj.control.dtexts[j]); kfree(se); + kfree(w->kcontrol_news[i].name); } kfree(w->kcontrol_news); } else { @@ -540,6 +541,7 @@ static void remove_widget(struct snd_soc */ kfree((void *)kcontrol->private_value); snd_ctl_remove(card, kcontrol); + kfree(w->kcontrol_news[i].name); } kfree(w->kcontrol_news); } @@ -1233,7 +1235,9 @@ static struct snd_kcontrol_new *soc_tplg dev_dbg(tplg->dev, " adding DAPM widget mixer control %s at %d\n", mc->hdr.name, i); - kc[i].name = mc->hdr.name; + kc[i].name = kstrdup(mc->hdr.name, GFP_KERNEL); + if (kc[i].name == NULL) + goto err_str; kc[i].private_value = (long)sm; kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; kc[i].access = mc->hdr.access; @@ -1278,8 +1282,10 @@ static struct snd_kcontrol_new *soc_tplg err_str: kfree(sm); err: - for (--i; i >= 0; i--) + for (--i; i >= 0; i--) { kfree((void *)kc[i].private_value); + kfree(kc[i].name); + } kfree(kc); return NULL; } @@ -1310,7 +1316,9 @@ static struct snd_kcontrol_new *soc_tplg dev_dbg(tplg->dev, " adding DAPM widget enum control %s\n", ec->hdr.name); - kc[i].name = ec->hdr.name; + kc[i].name = kstrdup(ec->hdr.name, GFP_KERNEL); + if (kc[i].name == NULL) + goto err_se; kc[i].private_value = (long)se; kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; kc[i].access = ec->hdr.access; @@ -1386,6 +1394,7 @@ err_se: kfree(se->dobj.control.dtexts[j]); kfree(se); + kfree(kc[i].name); } err: kfree(kc); @@ -1424,7 +1433,9 @@ static struct snd_kcontrol_new *soc_tplg "ASoC: adding bytes kcontrol %s with access 0x%x\n", be->hdr.name, be->hdr.access); - kc[i].name = be->hdr.name; + kc[i].name = kstrdup(be->hdr.name, GFP_KERNEL); + if (kc[i].name == NULL) + goto err; kc[i].private_value = (long)sbe; kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; kc[i].access = be->hdr.access; @@ -1454,8 +1465,10 @@ static struct snd_kcontrol_new *soc_tplg return kc; err: - for (--i; i >= 0; i--) + for (--i; i >= 0; i--) { kfree((void *)kc[i].private_value); + kfree(kc[i].name); + } kfree(kc); return NULL;