Message ID | 20240216130050.3786789-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-68606-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp494878dyb; Fri, 16 Feb 2024 05:04:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV1aMaLXqsmQafIYza0boTFDC3U2frvWs9KPmelGaG5CT3MVbGz0+Nt/0scIS4NKSqIKOci8IldvKuapt00/gT+NOWxvA== X-Google-Smtp-Source: AGHT+IGv3aEIJ69tKBCELkSO/4xtFtLkPyt7iSB7dRBMCXJ2UgpQ69BzUXwV703Xqgo3k+uO9JkL X-Received: by 2002:a17:90a:1f85:b0:299:9d8:d7c7 with SMTP id x5-20020a17090a1f8500b0029909d8d7c7mr4272068pja.10.1708088645753; Fri, 16 Feb 2024 05:04:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708088645; cv=pass; d=google.com; s=arc-20160816; b=ejtI3wf91cbaLuxRNphn73zFBrphJ0jBOMvuCsQGaYq2Qw/uH+hY7ESG8EXWGcQxll wKNSs52xhB2vpfBB/moGQ2bt6sIT90HrBgp3xEWZYINlP2ofwnVLMy8MiANhddItO2Gd EOIKmIEKt0/pYP8ZrgasKc+gVvNnfMHahLeOd2iVpckxdV85WCJtdDmA0wFGzAzQYWFJ irbiyOVVbJTVaVI0MHEzacRD9SNdLd79e9iU4fDWiOaKl4l5R2yYLQIqhDAWYQsutnTt rbZ7kXj2qEUqmPm/CLzASMpVIaS3pEHBkJQMgMAEDXX86leKb57WYSb4uxU8U3th+yPs dPUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=gMjWrfs/j53Qzy6FCJKjNtLvJjziSbKDMInGKymoK4U=; fh=quwBX+b90E4NNszB80nQd/QmNko5o9rWUFlgtwxWFA4=; b=CuaGpCQ69S+llU5ZY9BYx4LclyuFj9eGY5mduDusAOejlRjeDPWw/Sqn2UqBMe6Nle Aa941eXWSbLFsN86WntzKDoMyZznVu7nAEseZGMlS0l2MUV1bqkVXapYZ72i6AYDdUND AmTv6edn5feJhPFSwYVKWWl7TAQsRGLhf3maEUUMERv7//dULNmLS6wG32Mw6ozshNnd uFjtN978b7q0OgJxfMYh8PwWH4KuJjzWIPCPgbUEFOJvfqvNy0Tl3lb06CnMI1a+BgFw UWt51aFKAgWPRODj0DjFXhNuAze0V8e5RjbHLLopVVDNX0AanYRDjJ+rnhPr8hF0iJbx muYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qw9uyJj5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-68606-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68606-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x22-20020a17090a8a9600b0029930700dd8si1493709pjn.94.2024.02.16.05.04.05 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 05:04:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68606-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qw9uyJj5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-68606-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68606-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1D437B24C1C for <ouuuleilei@gmail.com>; Fri, 16 Feb 2024 13:01:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 209CE129A60; Fri, 16 Feb 2024 13:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qw9uyJj5" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 89A9012883D; Fri, 16 Feb 2024 13:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708088456; cv=none; b=UWWKLbHzHVIX76og69Hwx/QywNgy/TJ9YmZapaIzHzaxUdVEZrTTSE2FgluSKUMNGk7j8p9SUg96Mc5b/EK5DShaWXE04vzTtsO3j/bm5N6u851WS0GJyFVah1VYRfpQXHqmw9VJM8UfdaNIctZFsup4OxLj0v+iNLJ5d1d5CEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708088456; c=relaxed/simple; bh=cJk02p6GPEQNgHFZ7cmc8x6CZ4W/98+yT4cisVv1/94=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ZSu/kB3YQb7YT4TpgLZSe0fwHatE2QAobhiKzpS/uh92DGTC08kdNUUzsfTNzuz+eTDbSRnIV3aWD5tTtooeuE8UX/mze3LTYpdFOC35zgcs9sxpTqLOadBms3Er6C+NT2THzXFQVU8Sv5n6E6YbL2xNNLZsyQoheIVqrd5LaJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qw9uyJj5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81FF1C433C7; Fri, 16 Feb 2024 13:00:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708088456; bh=cJk02p6GPEQNgHFZ7cmc8x6CZ4W/98+yT4cisVv1/94=; h=From:To:Cc:Subject:Date:From; b=qw9uyJj5rL//tl/+WhqXqS0rS0sB2ZXF8MkSr/3r1VUYaiTzBWD76Oly4f4EIltKa AVjZfJdCzfNr7k7BYFIhok5cO4Go2c6rD4HrKBykHSlLaj5Dp/YIPRyzsoEiQdSKEx 7KSLzwMPltNIlkxwjXApheXGaxyLEjFG5vmyEV7sCvi3dEyhbCQMMNPxGufOsn89iN qBNz02XSSo7jHB12IbVFiSzG9gyzHmXssjvhezbcSj2tNKH7TFQQF0jrEY5jCkrFTI o1xJhxaI4CxOKWCqECdjLS0lgmt8ucFOdi3Z0/kyFWUNVs/yJT8/2FGXC6RxHONk72 /aeXCfhMJChcA== From: Arnd Bergmann <arnd@kernel.org> To: Ivan Orlov <ivan.orlov0322@gmail.com>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com> Cc: Arnd Bergmann <arnd@arndb.de>, Naresh Kamboju <naresh.kamboju@linaro.org>, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ALSA: core: fix buffer overflow in test_format_fill_silence() Date: Fri, 16 Feb 2024 14:00:36 +0100 Message-Id: <20240216130050.3786789-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791060760131526872 X-GMAIL-MSGID: 1791060760131526872 |
Series |
ALSA: core: fix buffer overflow in test_format_fill_silence()
|
|
Commit Message
Arnd Bergmann
Feb. 16, 2024, 1 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> KASAN caught a buffer overflow with the hardcoded 2048 byte buffer size, when 2080 bytes are written to it: BUG: KASAN: slab-out-of-bounds in snd_pcm_format_set_silence+0x3bc/0x3e4 Write of size 8 at addr ffff0000c8149800 by task kunit_try_catch/1297 CPU: 0 PID: 1297 Comm: kunit_try_catch Tainted: G N 6.8.0-rc4-next-20240216 #1 Hardware name: linux,dummy-virt (DT) Call trace: kasan_report+0x78/0xc0 __asan_report_store_n_noabort+0x1c/0x28 snd_pcm_format_set_silence+0x3bc/0x3e4 _test_fill_silence+0xdc/0x298 test_format_fill_silence+0x110/0x228 kunit_try_run_case+0x144/0x3bc kunit_generic_run_threadfn_adapter+0x50/0x94 kthread+0x330/0x3e8 ret_from_fork+0x10/0x20 Allocated by task 1297: __kmalloc+0x17c/0x2f0 kunit_kmalloc_array+0x2c/0x78 test_format_fill_silence+0xcc/0x228 kunit_try_run_case+0x144/0x3bc kunit_generic_run_threadfn_adapter+0x50/0x94 kthread+0x330/0x3e8 ret_from_fork+0x10/0x20 Replace the incorrect size with the correct length of 260 64-bit samples. Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> Fixes: 3e39acf56ede ("ALSA: core: Add sound core KUnit test") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- Naresh, I slightly changed the patch to make the computation more obvious, can you test again to make sure I got this right? --- sound/core/sound_kunit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 2/16/24 13:00, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > KASAN caught a buffer overflow with the hardcoded 2048 byte buffer > size, when 2080 bytes are written to it: > > BUG: KASAN: slab-out-of-bounds in snd_pcm_format_set_silence+0x3bc/0x3e4 > Write of size 8 at addr ffff0000c8149800 by task kunit_try_catch/1297 > > CPU: 0 PID: 1297 Comm: kunit_try_catch Tainted: G N 6.8.0-rc4-next-20240216 #1 > Hardware name: linux,dummy-virt (DT) > Call trace: > kasan_report+0x78/0xc0 > __asan_report_store_n_noabort+0x1c/0x28 > snd_pcm_format_set_silence+0x3bc/0x3e4 > _test_fill_silence+0xdc/0x298 > test_format_fill_silence+0x110/0x228 > kunit_try_run_case+0x144/0x3bc > kunit_generic_run_threadfn_adapter+0x50/0x94 > kthread+0x330/0x3e8 > ret_from_fork+0x10/0x20 > > Allocated by task 1297: > __kmalloc+0x17c/0x2f0 > kunit_kmalloc_array+0x2c/0x78 > test_format_fill_silence+0xcc/0x228 > kunit_try_run_case+0x144/0x3bc > kunit_generic_run_threadfn_adapter+0x50/0x94 > kthread+0x330/0x3e8 > ret_from_fork+0x10/0x20 > > Replace the incorrect size with the correct length of 260 64-bit samples. > > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> > Fixes: 3e39acf56ede ("ALSA: core: Add sound core KUnit test") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > Naresh, I slightly changed the patch to make the computation more obvious, > can you test again to make sure I got this right? > --- > sound/core/sound_kunit.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/sound/core/sound_kunit.c b/sound/core/sound_kunit.c > index 5d5a7bf88de4..7f16101ece7a 100644 > --- a/sound/core/sound_kunit.c > +++ b/sound/core/sound_kunit.c > @@ -8,7 +8,7 @@ > #include <sound/core.h> > #include <sound/pcm.h> > > -#define SILENCE_BUFFER_SIZE 2048 > +#define SILENCE_BUFFER_SIZE (sizeof(u64) * 260) I believe it would be good to define FILL_SILENCE_MAX_FRAMES to 260, update the 'buf_samples' array correspondingly and define the SILENCE_BUFFER_SIZE as (sizeof(u64) * FILL_SILENCE_MAX_FRAMES), so it would be more clear where '260' came from. Thank you for fixing this!
diff --git a/sound/core/sound_kunit.c b/sound/core/sound_kunit.c index 5d5a7bf88de4..7f16101ece7a 100644 --- a/sound/core/sound_kunit.c +++ b/sound/core/sound_kunit.c @@ -8,7 +8,7 @@ #include <sound/core.h> #include <sound/pcm.h> -#define SILENCE_BUFFER_SIZE 2048 +#define SILENCE_BUFFER_SIZE (sizeof(u64) * 260) #define SILENCE(...) { __VA_ARGS__ } #define DEFINE_FORMAT(fmt, pbits, wd, endianness, signd, silence_arr) { \ .format = SNDRV_PCM_FORMAT_##fmt, .physical_bits = pbits, \