Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8862238ybi; Tue, 23 Jul 2019 16:57:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlspVGAic/2KGBXnqRIyKvyHHUeshjEqT9TBdkg2js7JtWZ+ypeXrQuUdbp1LxaKHHxcrj X-Received: by 2002:a62:87c8:: with SMTP id i191mr8302446pfe.133.1563926272187; Tue, 23 Jul 2019 16:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563926272; cv=none; d=google.com; s=arc-20160816; b=ahyBJoCVpCXTgmmgv9G4LET1VO2XJU7oCCHwWUyd20Nhzc1pNtl6XsZbtZAJ2BsAFj 9DftnoROgVdK1srO6xGf+Kua6uqXxt+kHZN4FfCXF0Xh6q/vqzQdK5Q1g4EL/o8tpUHa 3ky0dYaKnsF+ZnRrM73jynU3jTC/FY5+l75yrQ82ozljr5CPVbbfLxa+ez3kWB8fRiZS G3yVXWbWng3jZ0w7gPNI315L6IfmCjxqnZ+MF8ywkijrtub8+8CRRRLiD6od8am5coUw ZNdrzFqFu1jmwHQudBFyPLitWs1H8jmDRCZa5fJ26QAhmqeuugty3yLDyrL2bROZfNYJ mjgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=FMDXCJhKssjuroUVGx8H5W+LEWpOIMy5/JePoD1Ib+0=; b=MMUE/EylcVtCAAlZAHANC4TwRHCYUstOVBj3EQtu9LuBMaByHw1ceSSadUd/0wc+sw 54XbH9tWeQWNLYQdf1QqJnH6uAcSu74xHhQKKI0gjvLk5G5tw8GL6DIMlR5GvmRuens8 as898ZomDpdg4osBNA2rzZ98y/ZXAkJ5IGAPVfCGFO381GXO92C9DGuxhMIhbWZND74q r7wZjTt8N94CzUjtP1xsbf7bXA/+eqYa2ggg7SprbyOuh+XU28umXkmlebOkKQVM775y uk293ONUNaPINotxXHXrJT5zDlFU+fpp7U7z61zn0HVohoVn9+o19hL6DSv7T1yk8f1T SeVA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s6si11050264pjq.108.2019.07.23.16.57.36; Tue, 23 Jul 2019 16:57:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390386AbfGWNrt (ORCPT + 99 others); Tue, 23 Jul 2019 09:47:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:39306 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726260AbfGWNrt (ORCPT ); Tue, 23 Jul 2019 09:47:49 -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 1BCF6AF7E; Tue, 23 Jul 2019 13:47:48 +0000 (UTC) Date: Tue, 23 Jul 2019 15:47:47 +0200 Message-ID: From: Takashi Iwai To: "Jia-Ju Bai" Cc: , , , , , Subject: Re: [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree() In-Reply-To: <20190723134020.25972-1-baijiaju1990@gmail.com> References: <20190723134020.25972-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 Tue, 23 Jul 2019 15:40:20 +0200, Jia-Ju Bai wrote: > > In snd_gf1_mem_xfree(), there is an if statement on line 72 and line 74 > to check whether block->next is NULL: > if (block->next) > > When block->next is NULL, block->next is used on line 84: > block->next->prev = block->prev; > > Thus, a possible null-pointer dereference may occur in this case. There is already a check beforehand: if (alloc->last == block) { and the code path you're referring to is only after this check fails, i.e. it's no last entry, hence block->next can be never NULL. So the current code is OK. thanks, Takashi > > To fix this possible bug, block->next is checked before using it. > > This bug is found by a static analysis tool STCheck written by us. > > Signed-off-by: Jia-Ju Bai > --- > sound/isa/gus/gus_mem.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/sound/isa/gus/gus_mem.c b/sound/isa/gus/gus_mem.c > index cb02d18dde60..ed6205b88057 100644 > --- a/sound/isa/gus/gus_mem.c > +++ b/sound/isa/gus/gus_mem.c > @@ -81,7 +81,8 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * blo > if (block->prev) > block->prev->next = NULL; > } else { > - block->next->prev = block->prev; > + if (block->next) > + block->next->prev = block->prev; > if (block->prev) > block->prev->next = block->next; > } > -- > 2.17.0 > >