Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1362940iog; Tue, 14 Jun 2022 04:47:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgdv/LfV0PVkkNSWb3A+4/0eexROahGuNJAMIP12MwybuTsTNq1Yd+hqqQeFJmiTFm57EM X-Received: by 2002:a17:907:3f02:b0:6f3:5c42:321a with SMTP id hq2-20020a1709073f0200b006f35c42321amr4011419ejc.521.1655207260632; Tue, 14 Jun 2022 04:47:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655207260; cv=none; d=google.com; s=arc-20160816; b=YMED/D9l7en1gx5IO5uhIEpTUUeILeNElhLoujOKsanDhSe5X3XbqwIYYGZcbY68z5 IyMnzANy4V7O9wsnzRSkdC2jUmDfx6iEc0rtd0j8Q+f0fT+qDMmg47vitz2eJnTEFCq0 WTsDRJ39uH+t/CXoC1PvH23isKBucaqgf9YeoMkzg/81vaLuVTLigYelSQ82X/OO1XDd iQhACxU2vWg098NlM4pREFozc/p0n1WZwYmkLesPAJHMXxO2S0CdVHiAhgFFwLlqsowI BnaBsd8bbO+HIUUKpgsCac6hAFqVQFZdDubU5jmWkN+biWyyC4lGKHyZ0KR856SuNzFD fkXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6fDkQC8ZKVocu1dwyc/psG+b89yWGBNWOILFDwfgnUw=; b=tfu95VfohZUdB3baeM1C4eiXwTDuGpaMs17e7VjqQeT5NWu3HlwqGiEulGluJCxxOn gPNmy9yPEOQ6w33LxXJyrsZvyYgs/0y2gzT6e11marhe1YCzIvBtaimlzVE3vGOC6EB6 sED6+EQQavfAt2P7jDvJ07t3PVgNQpuHpwcVuGKSmiNnIbGmG3yaClNdxMaRt10yTPA1 x7smFDhN50XdHguGxi9Kjv0gi0H3rSbDtFXrvGDYx376xW5qqHYq+kvkz0BXNjoCMb0F Wx4cFWkcY5rj4fEDSveai5hk3JNILEt77SntnnBwIO0Ie3ScGpNT8BhJZX0mEn7ilYyi JEaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MtIL12FT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb14-20020a0564020d0e00b0042e2e6a7a5fsi14296142edb.590.2022.06.14.04.47.15; Tue, 14 Jun 2022 04:47:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MtIL12FT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236211AbiFNLaT (ORCPT + 99 others); Tue, 14 Jun 2022 07:30:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234316AbiFNLaS (ORCPT ); Tue, 14 Jun 2022 07:30:18 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 820A33ED34 for ; Tue, 14 Jun 2022 04:30:17 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id w17so3351853wrg.7 for ; Tue, 14 Jun 2022 04:30:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6fDkQC8ZKVocu1dwyc/psG+b89yWGBNWOILFDwfgnUw=; b=MtIL12FTuJLbgfojZkdiHK2wuuXZukt1C8rtMBGRtkseg9nG3Dl2xlSUSmBKiGHiHW KrDSL0uDk0ugVeO/B/S3mFMfpN3TQqMrq+ZxAmF8h9OpeoVU06DBJ8C0IAdo3mm1uhP2 HMJgbIsqRADUfnNYNC6p1e+v2kR/Jd/E3b9Kbt2ked5zeQaYXcquj5bEZdCDBYXmlFwz IQvPcqIXnDQwYyvoShiDS5RQbXpmfAvMIX5HZiqo3MfYq3n42B2aw4Oqy4ED03baNz+J geycRa52J5H6Rf4W5rmzI+NEOP7TEqP1rwYXTfPwZpu9FJ+QjbJ+17H6/HhAHLuM7K3m wZCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6fDkQC8ZKVocu1dwyc/psG+b89yWGBNWOILFDwfgnUw=; b=CPF0amsAxWUHYyDeJkJNXf1G0U+KG+r8GfiWQbCs2dEFK2KpjQP98QMxw6ABv7e59o lO1GdaADTctGgJKtL9mGXTujpwvRqk/t15CAi40XHpc5qT+4GMJ83haIEIdSNPxcS3rS X7psjfbOaWp+vtlH3kDfNuuObvZkubnvcRqfYaDSr+gltB8gJGKQYrebxvZH98kC3zs4 9+T568q4uXvJXll2K8Zd58JWr//bHrHxQfjsTkdZyBzbBYDwXxDbMletWUaQSQ/BpLqP iP5jn+TwgoBrhNl1F51iupvygtHFGs22zGDk0yvJmCOIiEVCDQl2Mmjn4mxwTveHKPZH 1N9A== X-Gm-Message-State: AJIora/d83cSiEA+qhFy34gatkN7u4tQxgGyjN/jlxnUfl8aREzu6++5 ENS74EF7nXxdcPX1A1SZGoY= X-Received: by 2002:a05:6000:a10:b0:21a:14e2:794 with SMTP id co16-20020a0560000a1000b0021a14e20794mr4573888wrb.428.1655206216031; Tue, 14 Jun 2022 04:30:16 -0700 (PDT) Received: from opensuse.localnet (host-87-16-96-199.retail.telecomitalia.it. [87.16.96.199]) by smtp.gmail.com with ESMTPSA id i8-20020adffc08000000b0020c5253d8d0sm11365134wrr.28.2022.06.14.04.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 04:30:14 -0700 (PDT) From: "Fabio M. De Francesco" To: Takashi Iwai Cc: Eugeniu Rosca , Jaroslav Kysela , Takashi Iwai , Mark Brown , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, syzbot+205eb15961852c2c5974@syzkaller.appspotmail.com, naveenkumar.sunkari@in.bosch.com, Eugeniu Rosca Subject: Re: [PATCH] ALSA: pcm: Test for "silence" field in struct "pcm_format_data" Date: Tue, 14 Jun 2022 13:30:13 +0200 Message-ID: <8079585.T7Z3S40VBb@opensuse> In-Reply-To: <87y1xzplj1.wl-tiwai@suse.de> References: <20220409012655.9399-1-fmdefrancesco@gmail.com> <2245197.ElGaqSPkdT@opensuse> <87y1xzplj1.wl-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On marted=C3=AC 14 giugno 2022 12:49:38 CEST Takashi Iwai wrote: > On Tue, 14 Jun 2022 12:43:16 +0200, > Fabio M. De Francesco wrote: > >=20 > > On marted=C3=AC 14 giugno 2022 11:58:51 CEST Eugeniu Rosca wrote: > > > Hello Fabio, hello All, > > >=20 > > > On Sa, Apr 09, 2022 at 03:26:55 +0200, Fabio M. De Francesco wrote: > > > > Syzbot reports "KASAN: null-ptr-deref Write in > > > > snd_pcm_format_set_silence".[1] > > > >=20 > > > > It is due to missing validation of the "silence" field of struct > > > > "pcm_format_data" in "pcm_formats" array. > > > >=20 > > > > Add a test for valid "pat" and, if it is not so, return -EINVAL. > > > >=20 > > > > [1] https://lore.kernel.org/lkml/ > > 000000000000d188ef05dc2c7279@google.com/ > > > >=20 > > > > Reported-and-tested-by:=20 > > syzbot+205eb15961852c2c5974@syzkaller.appspotmail.com > > > > Signed-off-by: Fabio M. De Francesco > > > > --- > > > >=20 > > > > I wasn't able to figure out the commit for the "Fixes:" tag. If=20 this=20 > > patch > > > > is good, can someone please help with providing this missing=20 > > information? > > > >=20 > > > > sound/core/pcm_misc.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > >=20 > > > > diff --git a/sound/core/pcm_misc.c b/sound/core/pcm_misc.c > > > > index 4866aed97aac..5588b6a1ee8b 100644 > > > > --- a/sound/core/pcm_misc.c > > > > +++ b/sound/core/pcm_misc.c > > > > @@ -433,7 +433,7 @@ int snd_pcm_format_set_silence(snd_pcm_format_t= =20 > > format, void *data, unsigned int > > > > return 0; > > > > width =3D pcm_formats[(INT)format].phys; /* physical width */ > > > > pat =3D pcm_formats[(INT)format].silence; > > > > - if (! width) > > > > + if (!width || !pat) > > > > return -EINVAL; > > > > /* signed or 1 byte data */ > > > > if (pcm_formats[(INT)format].signd =3D=3D 1 || width <=3D 8) { > > >=20 > > > JFYI, PVS-Studio 7.19 reports: > > >=20 > > > sound/core/pcm_misc.c 409 warn V560 A part of=20 > > conditional expression is always false: !pat. > >=20 > > Sorry, I assumed (wrongly!) that when we have > >=20 > > static const struct pcm_format_data=20 > > pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] =3D { > > [SNDRV_PCM_FORMAT_S8] =3D { > > .width =3D 8, .phys =3D 8, .le =3D -1, .signd =3D 1, > > .silence =3D {}, > > }, > > [snip] > > /* FIXME: the following two formats are not defined properly yet=20 > > */ > > [SNDRV_PCM_FORMAT_MPEG] =3D { > > .le =3D -1, .signd =3D -1, > > }, > > [SNDRV_PCM_FORMAT_GSM] =3D { > > .le =3D -1, .signd =3D -1, > > }, > >=20 > > pointer "silence", and then "pat", must be NULL. >=20 > Oh right, those are missing ones. I haven't realized that those > formats are allowed by PCM OSS layer. >=20 > Practically seen, those formats have never been used in reality, and > we may consider dropping them completely to plug such holes... >=20 Does it imply that my argument is correct or my "fix" can't yet catch those= =20 missing ones? Besides the question above, I want to notice that we have one more /* FIXME= =20 */ entry... /* FIXME: the following format is not defined properly yet */ [SNDRV_PCM_FORMAT_SPECIAL] =3D { .le =3D -1, .signd =3D -1, }, If you want I can get rid of those three entries if you confirm they can=20 safely be deleted. In a second patch I can also remove that unnecessary=20 check for valid "pat". Please let me know. Thanks, =46abio