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 93E36C7618B for ; Wed, 24 Jul 2019 12:32:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A8EF214AF for ; Wed, 24 Jul 2019 12:32:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728343AbfGXMcG (ORCPT ); Wed, 24 Jul 2019 08:32:06 -0400 Received: from mx2.suse.de ([195.135.220.15]:60050 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726558AbfGXMcF (ORCPT ); Wed, 24 Jul 2019 08:32:05 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A13D8B11E; Wed, 24 Jul 2019 12:32:04 +0000 (UTC) Date: Wed, 24 Jul 2019 14:32:04 +0200 Message-ID: From: Takashi Iwai To: "Jia-Ju Bai" Cc: , , , , , , , Subject: Re: [PATCH] ALSA: core: Fix possible null-pointer dereferences in snd_timer_proc_read() In-Reply-To: <20190724121327.9894-1-baijiaju1990@gmail.com> References: <20190724121327.9894-1-baijiaju1990@gmail.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 Wed, 24 Jul 2019 14:13:27 +0200, Jia-Ju Bai wrote: > > In snd_timer_proc_read(), there is an if statement on line 1204 to check > whether timer->card is NULL: > if (timer->card && timer->card->shutdown) > > When timer->card is NULL, it is used on lines 1212 and 1215: > timer->card->number > > Thus, possible null-pointer dereferences may occur. > > To fix these bugs, timer->card is checked before being used. Both cases can (should) never happen. The SNDRV_TIMER_CLASS_CARD is always associated with a timer with a card object. Ditto for SNDRV_TIMER_CLASS_PCM, where a PCM is always tied with a card. So, if any, this should be a WARN_ON(). But I doubt it being any useful. thanks, Takashi > > These bugs are found by a static analysis tool STCheck written by us. > > Signed-off-by: Jia-Ju Bai > --- > sound/core/timer.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/sound/core/timer.c b/sound/core/timer.c > index 5c9fbf3f4340..967d06a3cdec 100644 > --- a/sound/core/timer.c > +++ b/sound/core/timer.c > @@ -1208,11 +1208,13 @@ static void snd_timer_proc_read(struct snd_info_entry *entry, > snd_iprintf(buffer, "G%i: ", timer->tmr_device); > break; > case SNDRV_TIMER_CLASS_CARD: > - snd_iprintf(buffer, "C%i-%i: ", > - timer->card->number, timer->tmr_device); > + snd_iprintf(buffer, "C%i-%i: ", > + timer->card ? timer->card->number : -1, > + timer->tmr_device); > break; > case SNDRV_TIMER_CLASS_PCM: > - snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number, > + snd_iprintf(buffer, "P%i-%i-%i: ", > + timer->card ? timer->card->number : -1, > timer->tmr_device, timer->tmr_subdevice); > break; > default: > -- > 2.17.0 > >