Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8862851ybi; Tue, 23 Jul 2019 16:58:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzg3wBjA62f3rBDl6Fv81641u5aW+M3Kg10TfphcVPILSB86BTXFIV5GY8vtW8wwZUB4SP6 X-Received: by 2002:a17:902:b28b:: with SMTP id u11mr79254839plr.11.1563926316440; Tue, 23 Jul 2019 16:58:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563926316; cv=none; d=google.com; s=arc-20160816; b=bxkB6l3ZOVnyW3BZVLF0kVkgHWEu0FRtWVmjDbAo3MvVQa3wlhGEd29Q3RUKjgj8il xEIAej/OKcsNmBln1bzmOeRPOJAf0vgiUSsjNCNhUsqQvfpRISbeduWtUB/Ct6tuP38L XEKIHevMn7xk2eLVF4bpBY9lFOAVECcT2mAckjSv+MhXJPWU+t13YW2H5I9YTJ1j+DVr sIx8BSLcfm5fxnDd1hu7IvNWlwHpQhBP/0mpD9uULA+Gz30/GGLETUSpV/VUnZVyk0E+ 1iyToux0uWYLZH5oF8SVH9mcNGpGmz8l4aZfnmk63avXhQRYOi/+yo1RZrMV8MlUt4EO re2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=iieAYOuoQNwyrS3dY4/FXtAdVnIv4y3zEt6WfnxberI=; b=K/yOX28uLkbUE9xwl2WazH8UjMrPsk+4vGpkgRhmKnI2cdC93CEIk9Xby7+O8D58Qg Hk+hSpkb0L5ZBSDvFEpkg1zsk1LxukDPFQWPE5AL2Y/uZYo3MkH6qmSvoulaUpmYQO8R LliF1FvkLfq/s1htmvIJFL1ZTz9bUmM9Tx83WoCH2gBcVDsWP/nIE5n0YmvUS5EMfI1N MGtrsUeW5vv0HQwjpGPkFvSeFOEo0HUbUhF1DFLY9Hy97PlI+3tYlQ8YvEvJcRdFKG7H AGBVGe+iNiMpkAofFRvfnaKmt4LZObpWzbmAJwL2C8p43qfZ5CeXkXJ7vEzfkmlQwyu/ CgLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QBi2yLUH; 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 f37si4595576pgm.145.2019.07.23.16.58.20; Tue, 23 Jul 2019 16:58:36 -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=QBi2yLUH; 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 S1732945AbfGWNv3 (ORCPT + 99 others); Tue, 23 Jul 2019 09:51:29 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36834 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726527AbfGWNv3 (ORCPT ); Tue, 23 Jul 2019 09:51:29 -0400 Received: by mail-pg1-f193.google.com with SMTP id l21so19473605pgm.3 for ; Tue, 23 Jul 2019 06:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=iieAYOuoQNwyrS3dY4/FXtAdVnIv4y3zEt6WfnxberI=; b=QBi2yLUHpAPrxVmIpm/So8E76VZkVKgKQcUchzNQ3F1+wpsRGN4CV2XRnMhmZIJfEz 6zBaRa3wzEBgZK/TXJ4Jt69RuxOpBVo4HYvMxIRE85lKV/yqrs5OwKo/HwV9xivvdHWZ +FdiDnRN/6xO7MI0K2lNaPgIEGxK5mZDJCIdYYPYlQD/MoLxUFSShEXYz8XQOdPrEm9y OuC7zvaZ1dRddcDNYaptRuyybKnf+T+8GASIkZeze7kLcRpauuCM4vq1TZk2EFW9/Eqz n6OqYPipcMGnjXRTtCA6ojoDIe90pGcN0ln3VTmEkv0fxhu6NQWCOgpTtuJR7AhLkhbD WnuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=iieAYOuoQNwyrS3dY4/FXtAdVnIv4y3zEt6WfnxberI=; b=RErRy4iWX7ewcYs0Py2aKdxgubCRt/tIFvODC/OWqBD001Vf+npv2OxJriROCblIrg F2jn414DCi/g/sw/kxcT7yZE4x+BzKyJ6mKFS1a3nG9P+63Uq2eymW4RIMakrK5OsHiC 0QgP6ToZYR10CTP1PU1+vSc+FEZPdEwfgmCsYfvyf50VcX9ClcXnpwvSxt4s4RGTizxO DHISXwBXT5hw2gycWzOK0peS9IB/y2xYvvli7GWVYZrCjJb568zpcuipyqw40lhOyWKB 3y/DM5hqxut7h7xQ6mlznNOql0AhEoSq9wTiLGUQPID8AYYVKM8pTFLXVvl98V4Ql4GN 4U/A== X-Gm-Message-State: APjAAAUMe3m7GuGWg0GghP6DtopqPzoqkPe9kR0k6tOQnzUNIpzJEPZV 4KNvknhbBmWU3Zzy8xaRj2XikpkE X-Received: by 2002:a62:2b81:: with SMTP id r123mr5701513pfr.108.1563889888708; Tue, 23 Jul 2019 06:51:28 -0700 (PDT) Received: from ?IPv6:2402:f000:4:72:808::177e? ([2402:f000:4:72:808::177e]) by smtp.gmail.com with ESMTPSA id q21sm27138226pgb.48.2019.07.23.06.51.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jul 2019 06:51:28 -0700 (PDT) Subject: Re: [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree() To: Takashi Iwai Cc: huangfq.daxian@gmail.com, tglx@linutronix.de, allison@lohutok.net, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org References: <20190723134020.25972-1-baijiaju1990@gmail.com> From: Jia-Ju Bai Message-ID: <57696d77-922b-51d6-0623-5c6f4fe2b972@gmail.com> Date: Tue, 23 Jul 2019 21:51:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for the quick reply :) I think you are right, and I did not consider "if (alloc->last == block)" Sorry for the false report... Best wishes, Jia-Ju Bai On 2019/7/23 21:47, Takashi Iwai wrote: > 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 >> >>