Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10825409ybi; Thu, 25 Jul 2019 05:48:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9jxeZXAS5TGirSYFuG5JkdGZuJ2kqRjQPIH7sbhMrmmklP1VviQ64W+uWW9FCjq6HenGA X-Received: by 2002:a63:5754:: with SMTP id h20mr45778137pgm.195.1564058930361; Thu, 25 Jul 2019 05:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564058930; cv=none; d=google.com; s=arc-20160816; b=GrX5DNyTkZt/y3+glzw1UF8bqBiJ3YQe++z6fLokYFKyzQswsqLnxwWcA/USC3V+ql 5+DVMTneZrqJHznR8HsVjyKxDmGbxV/NviK7dx9ZAhQg34/7d/aDh6WVlunGvT3RKVzG z2FWSl1VQmGOSzVG149xh2isRZtwJvYjdc9G4bQ+rcq2wITmml+vLk0tL1wYLwAmeh9Y AaqOeJ4FxXwttSwbEo+vkYLJWfU/6BQvL2ruME6smy7ZBHy1/0tG2t8C9aqkTAXhecJL MoLsNXV5A9egrkBS2nHhviUd1/Yu0LmNKkplpzfiND3Sfy5EuoIbOCoqMd2e1hgoOI92 laSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=XrnR0ob5JN+jXhmz3b6uLie9luXhbO1bl9luxd0o9lU=; b=L3m74ZyZ/1lVQDDKtRYWqlRFx8gxQ37xQgcTPHBxs4KdeA5vqp/Cal0DYKp76QTgoz sni82G3Lsfo6h/86xqfsVJ1DVCm07eYfr1j5wt4sBuWz8NBIR1pRegYvRmeeB12+jZh9 wavf2ycmob4nbABAu3wyDTo/nXYoo14Zm/FMnyJQoSyyDh/V760mohab0lwfvTLv/RVl PIt9iTswt91ln7KG70Dn/rsktXuoDAnOdOFy9JXQ064VkJI6YzIG0rK7Aod8eZU2Q8fU /FA8sKOpRRZLCvjLGu9md3B7lSWvu06oKJhhw9IXGrxb3aJhIt9RKVMIPBKzcMSKjBWA Gf4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uEdHBdGN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k17si18729475pgg.426.2019.07.25.05.48.36; Thu, 25 Jul 2019 05:48:50 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uEdHBdGN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389646AbfGYI1m (ORCPT + 99 others); Thu, 25 Jul 2019 04:27:42 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41907 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389623AbfGYI1l (ORCPT ); Thu, 25 Jul 2019 04:27:41 -0400 Received: by mail-pl1-f196.google.com with SMTP id m9so23022047pls.8 for ; Thu, 25 Jul 2019 01:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=XrnR0ob5JN+jXhmz3b6uLie9luXhbO1bl9luxd0o9lU=; b=uEdHBdGN1tspb+2pw1vjjIP9TPRoE69vcLhIkbQ3Buu7aF3UPsHXWe2IGuA3tRNBVq eZXOen8g79oqskTFwJi1T4z8wTYMs5sHGS0dqZWc/XYrk3vIl90BAeCwfVc+QcLwYOQz 684c2rKuEzuenlNVqPQqjGAjSAeU3XELQqNfmTeBKmIgEEhwTS98qHi5dH17lvRp0YYC s6m0F+PUjW1Agvc//exnF281ZadBdvEmKtcTVmcM4wsV2N3OFyRGwROU1WbmN1p0uxrN 60cn7S8wSpSNHW/6RJ3ewRADxQ2F1NIrCVVYAo4bhsdyT7rNAgsxSWrJB+GgjsoyU1uJ Rx2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=XrnR0ob5JN+jXhmz3b6uLie9luXhbO1bl9luxd0o9lU=; b=SWGxaRhKlKg84l6IN84NL13Pu0j+NgxtOxXauZhBBoXIMBUcGw/Ono9Ym2mTbNOf2n NdlVqBYrGuPGtBAQ5P07sYX4drWdaHtrAPqPCeSUibPIJkwxX/ky+UgOwq0cDLjSDle9 uehHGTdhd/9eXDnU8+UN9EpZHG+Ai1G8E/Yw6+2WbADEJkMDM4lHGpSTYR0v747nPUaQ j5+k2f4HqG+zTUymN4Pze3ltrpvKxyfDsrpQrbA1yAj6Tq46MVhKbfmvlda+tWnp2txg A8TmXxi5IWWI9C/o0SD1beKbncFKH9uhna89g+91irtKQV+UzeYF8KLKSHjZUN32P1e2 xcgQ== X-Gm-Message-State: APjAAAUgP0vRViTsc6LzmLFWIwYefKtRm7bv6IYGfi15DrIo6CYgHxL/ 8SXYAEUO28L69jr2qjs5rEHzI5u17QQ= X-Received: by 2002:a17:902:e383:: with SMTP id ch3mr89404861plb.23.1564043260596; Thu, 25 Jul 2019 01:27:40 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id 201sm58677399pfz.24.2019.07.25.01.27.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jul 2019 01:27:39 -0700 (PDT) From: Jia-Ju Bai To: perex@perex.cz, tiwai@suse.com, gregkh@linuxfoundation.org, tglx@linutronix.de, rfontana@redhat.com Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] ALSA: i2c: ak4xxx-adda: Fix a possible null pointer dereference in build_adc_controls() Date: Thu, 25 Jul 2019 16:27:33 +0800 Message-Id: <20190725082733.15234-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In build_adc_controls(), there is an if statement on line 773 to check whether ak->adc_info is NULL: if (! ak->adc_info || ! ak->adc_info[mixer_ch].switch_name) When ak->adc_info is NULL, it is used on line 792: knew.name = ak->adc_info[mixer_ch].selector_name; Thus, a possible null-pointer dereference may occur. To fix this bug, referring to lines 773 and 774, ak->adc_info and ak->adc_info[mixer_ch].selector_name are checked before being used. This bug is found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- sound/i2c/other/ak4xxx-adda.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c index 5f59316f982a..9a891470e84a 100644 --- a/sound/i2c/other/ak4xxx-adda.c +++ b/sound/i2c/other/ak4xxx-adda.c @@ -775,11 +775,13 @@ static int build_adc_controls(struct snd_akm4xxx *ak) return err; memset(&knew, 0, sizeof(knew)); - knew.name = ak->adc_info[mixer_ch].selector_name; - if (!knew.name) { + if (! ak->adc_info || + ! ak->adc_info[mixer_ch].selector_name) { knew.name = "Capture Channel"; knew.index = mixer_ch + ak->idx_offset * 2; } + else + knew.name = ak->adc_info[mixer_ch].selector_name; knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; knew.info = ak4xxx_capture_source_info; -- 2.17.0