Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1102439rdb; Tue, 30 Jan 2024 08:00:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDxYFazuZpPNuSYIKjePDpG1a+MkfVeHYOx86As5ncm4mRqKU3YWecVB7BWlcPAq6tsWLL X-Received: by 2002:a05:622a:1f8b:b0:42a:4889:b12 with SMTP id cb11-20020a05622a1f8b00b0042a48890b12mr12886149qtb.33.1706630432287; Tue, 30 Jan 2024 08:00:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706630432; cv=pass; d=google.com; s=arc-20160816; b=O3o+My6kVqAdMWJOrnK7PetNd7cB8i/NSnD4W1DHr/QIyYsMdkPvegql9vR+ZTIv8H E14MshX8wTUzx1mcUiIOftpLUiKxs2V8EyRHTGZ4/QmWq5rMLghMfVCatdgWfIBaLlmT 4mI4M9SEshzaCEAVlwWbuhD7DOG+PhlHxhjFz0ocHy2Hx+aFizH6qDouHKwKqVOKIkYX lwFoWjH74kPKzo86VX53jOsbaUnUJDt7J/dwkuSN9vzuwd+9B+79v/QIOJB7Z8PKgVwQ onfzFhhZ1/DAdYynWiIkYQHhRQO8lCulzE52kKLROkIroFaYpf79H3lxcwxyTxcO/b8H poIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=ge9gvNgXz8L2meeNEwfNhmZkY1eYZ+GxKdn9IeI42Mo=; fh=z9UjYQGNoRPXOvHMNbmgKt9M3cO+rxWDFiFdAbniO+w=; b=Iu/dq6mhzVtLsOF598SvpuFttSYt7ZQqQ1HiywlwGzD+CH0f3xIiWb7azttm7fdxdo l6x77mdQoujXfGi2Fs0MNBc6t+HrsoiREw0aLiDjZTfbQOKo4fVqvVezUSHyJixjEidj Quq7FycXpjYb+WJuD9wjRLp/EHdNWtb3FhdWzHCnQuG/aBcdjt4aZ3jnOmwmoV1RSqBP hUHGO1DylJSWuQN/qtY5yPOdEpsLewiLjLtckze3RnDY5KtZ3lbsw3CRwaxzFV+ort80 r1wL4H/t0gG2kew8KyfUIU5opFq9DKr8Hl9KUiZVEQte7nQrwrFTxZJ+XKtukPfXGXj2 I/8w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lixVOgru; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-44331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d18-20020a05622a15d200b0042b4e02d50esi1051055qty.402.2024.01.30.08.00.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 08:00:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lixVOgru; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-44331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 50B431C2478D for ; Tue, 30 Jan 2024 10:01:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C871664A9; Tue, 30 Jan 2024 09:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lixVOgru" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B921265BCD; Tue, 30 Jan 2024 09:56:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706608608; cv=none; b=XvAsafkaoU1arseMb/KzurWN/mAlU58LehRo8FmexkWCIWl7qbqVoD4WuhOa4h7+8l7/mKQeCQuPeu2Vnyw0un96Y7OmrQGGJBU1/Qa0tfE9QyVDUbH45032LCh7nhFX8rVVwY43f/p2y/7DDDckxttWNvLaIqRTSj9mf4l5Gtg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706608608; c=relaxed/simple; bh=2VPEHzexv7amn45miqUGZIow01lrVch6FhfSAsTulbI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oBNB0qO8FsFXDEm7KA4cu1gtg/e0k41OwuP7ZxQhs/TrxcZUtlGbXUyJxpJ76aynbgWjx1CFiG3AjWTaaf+Cn3CvX/isooA9CtXMlvVGTE7CpFCwICJV6oLVk1J7iGAjSkrQUlbFX8e8crHkrac0QB47z6iIWrIfp5M8629J/SU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lixVOgru; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706608607; x=1738144607; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=2VPEHzexv7amn45miqUGZIow01lrVch6FhfSAsTulbI=; b=lixVOgruDwwDPGQWr4a0FcxSnnTj5bSXkAfyUjs5dOLvVDfkvstg2ctR YsZ2m3ttn01ndURRrTfuUbxlKMFCc5B/uaRh2q3AA0bLrhKgpO18/bXUe fpL+Id9e0ex60HKrd+P3Q7czELTNmi9cAILBOGxIIfU382+kj6MpYSH1A Ma7GfUmI0om2oXoqRbe34S6HxDEPnptfYCjcjmmtgYhNDu4GNH7nD3Ukl YjYv5Ao1vRDx/jNuEmbyCMhXPCEteUJYYsQP9cYG47YfkZndLU/HPGvDW 4U9fyzzrpm/rsKJZggLoICmewnv8lIv+yzDBXbHaSFmwu2T01IcssRQ4X A==; X-IronPort-AV: E=McAfee;i="6600,9927,10968"; a="21747643" X-IronPort-AV: E=Sophos;i="6.05,707,1701158400"; d="scan'208";a="21747643" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 01:56:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,707,1701158400"; d="scan'208";a="29852762" Received: from aslawinx-mobl.ger.corp.intel.com (HELO [10.94.8.107]) ([10.94.8.107]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 01:56:43 -0800 Message-ID: <8c92d33d-923b-4805-abdf-752e8943072e@linux.intel.com> Date: Tue, 30 Jan 2024 10:56:41 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sound: soc: wcd934x: fix an incorrect use of kstrndup() Content-Language: en-US To: Fullway Wang , broonie@kernel.org, srinivas.kandagatla@linaro.org, bgoswami@quicinc.com, tiwai@suse.com Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, fullwaywang@tencent.com References: From: =?UTF-8?Q?Amadeusz_S=C5=82awi=C5=84ski?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/18/2024 8:52 AM, Fullway Wang wrote: > In wcd934x_codec_enable_dec(), kstrndup() is used to alloc memory. > However, kmemdup_nul() should be used instead with the size known. > > This is similar to CVE-2019-12454 which was fixed in commit > a549881. > > Signed-off-by: Fullway Wang > --- > sound/soc/codecs/wcd934x.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/sound/soc/codecs/wcd934x.c b/sound/soc/codecs/wcd934x.c > index 1b6e376f3833..4565a0e1877f 100644 > --- a/sound/soc/codecs/wcd934x.c > +++ b/sound/soc/codecs/wcd934x.c > @@ -4990,7 +4990,7 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w, > char *dec; > u8 hpf_coff_freq; > > - widget_name = kstrndup(w->name, 15, GFP_KERNEL); > + widget_name = kmemdup_nul(w->name, 15, GFP_KERNEL); > if (!widget_name) > return -ENOMEM; > This change looks weird to me, and looking at code I'm even more confused. As far as I can tell code tries to find a number in w->name. It shouldn't need a duplicate string for this, it can search in existing one, same applies to referenced commit. And when it comes to a549881 as already mentioned in https://lore.kernel.org/alsa-devel/7573d8ce-7160-39b1-8901-be9155c451a1@suse.cz/ the size is at most 15 not equal to, so change was misguided. If you look at actual code widget name is around 8 characters. Also it seems like consensus was that CVE was bogus and it was a wrong change: https://lore.kernel.org/alsa-devel/20190618230527.GE6248@lindsey/ there was a revert send, but it seems like it was not applied: https://lore.kernel.org/alsa-devel/20190612133040.5kgtio7gidxx64gh@xylophone.i.decadent.org.uk/