From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F55BC33C9E for ; Tue, 14 Jan 2020 20:01:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DEC2724656 for ; Tue, 14 Jan 2020 20:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728761AbgANUBJ (ORCPT ); Tue, 14 Jan 2020 15:01:09 -0500 Received: from mx2.suse.de ([195.135.220.15]:39092 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726523AbgANUBI (ORCPT ); Tue, 14 Jan 2020 15:01:08 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D270DAF63; Tue, 14 Jan 2020 20:01:06 +0000 (UTC) Date: Tue, 14 Jan 2020 21:01:06 +0100 Message-ID: From: Takashi Iwai To: Colin King Cc: Jaroslav Kysela , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ALSA: hda - fix out of bounds read on spec->smux_paths In-Reply-To: <20200114154412.365395-1-colin.king@canonical.com> References: <20200114154412.365395-1-colin.king@canonical.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 14 Jan 2020 16:44:12 +0100, Colin King wrote: > > From: Colin Ian King > > It is possible for the call to snd_hda_get_num_conns to fail and return > a negative error code that gets assigned to num_conns. In that specific > case, the check of very large values of val against num_conns will not > fail the -EINVAL check and later on an out of bounds array read on > spec->smux_paths will occur. Fix this by sanity checking for an error > return from the call to snd_hda_get_num_conns. Thanks for the patch, but this can't happen. The ad1988_auto_smux_enum_put() is used only for IEC958 Playback Source element, and it's added in ad1988_add_spdif_mux_ctl(). And there at the beginning, there is already a check of the value: num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1; if (num_conns != 3 && num_conns != 4) return 0; And the snd_hda_get_num_conns() function returns the cached value, hence it's always same at the second and later calls, so it can't be a negative error. That said, I don't think we need to apply the change as is. But if we were to improve something, we can rather record this number more explicitly e.g. introduce a new field spec->num_spdif_mux_conns and keep there instead of calling snd_hda_get_num_conns() at each place. thanks, Takashi > > Addresses-Coverity: ("Out-of-bounds read") > Fixes: 272f3ea31776 ("ALSA: hda - Add SPDIF mux control to AD codec auto-parser") > Signed-off-by: Colin Ian King > --- > sound/pci/hda/patch_analog.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c > index 88c46b051d14..399561369495 100644 > --- a/sound/pci/hda/patch_analog.c > +++ b/sound/pci/hda/patch_analog.c > @@ -756,9 +756,11 @@ static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol, > struct ad198x_spec *spec = codec->spec; > unsigned int val = ucontrol->value.enumerated.item[0]; > struct nid_path *path; > - int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1; > + int num_conns = snd_hda_get_num_conns(codec, 0x0b); > > - if (val >= num_conns) > + if (num_conns < 0) > + return num_conns; > + if (val >= num_conns + 1) > return -EINVAL; > if (spec->cur_smux == val) > return 0; > -- > 2.24.0 >