Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4636126yba; Tue, 30 Apr 2019 01:37:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4OKkNQfcsdgTrA17URg0XsmGSVSo9mR7zyrsHOa03H3vSzj9qXwg73d2W/HCSdO02Gs4y X-Received: by 2002:a17:902:5a8f:: with SMTP id r15mr33161860pli.196.1556613437684; Tue, 30 Apr 2019 01:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556613437; cv=none; d=google.com; s=arc-20160816; b=tWLEvOyY950d6vBtOHoB+v8BuaLR0Gd+q2S211WXKECeHKNEJEpFe3O+4gAika84jS UTfmsMpKVT8u1u563PaEfTffh6mMDEexwCpQ7YENgTZHjCFwpe84+UUSFnNoxMgRFTqm aMzoJ4aTpikJHP9iinQbpMmjxrdnS594okGwnT5s50fex6Ut7S0bihsLOEY40YxEYA87 Kcx/F8vfDLiN9knuEWOR3hi3a3gQ/KeYl+lhZDJ4/anEgkDLEQ1qHGCRF4Zhvgm9gSiy lR0IVhBpRCc1JdC8AjUDrQf1rn6tPSIeM2Ahi21zTT40k48h4mgch8PZlOxLqgs/wAPw oz6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id; bh=vA1DDArEPdkUUD4bES6HwpWBCqNnJApMQwQNA2/2vRY=; b=mKXyM8tz/Wx8tej/oQ5hEcvf5D8+gKmGfRpe+oU4rjyaLDTl3Ok9eQeSydwUV7rKty HAyysufbn1sobTiOQbDWKa2xgRANQILhQCVPowDLkIeX31zHoUD3jsveFbHnr2VsDe5v twwCrfGymOwOAD3Afn7JqMRb7fgIAVki+HDcVfEItRqypZzFJKAbpy1DieG0pSYwtN1x hgdMFnS1gjWxPNMQjtZ3AexNHsW+Tifft/jIlkY+GRpHU3jOPfMwwdTKqo+z0bmnHefa rVwsqo7P8q7UUDjKJGh8+oRTC4h0fJ0in6gXtW774a4nFC5t2dznXYKyCMpSkoTfaHlx cypQ== 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 2si23363752plc.371.2019.04.30.01.37.02; Tue, 30 Apr 2019 01:37:17 -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 S1726520AbfD3IgK (ORCPT + 99 others); Tue, 30 Apr 2019 04:36:10 -0400 Received: from mail5.windriver.com ([192.103.53.11]:39538 "EHLO mail5.wrs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725790AbfD3IgK (ORCPT ); Tue, 30 Apr 2019 04:36:10 -0400 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id x3U8Wxfo014580 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 30 Apr 2019 01:33:15 -0700 Received: from [128.224.162.229] (128.224.162.229) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server id 14.3.439.0; Tue, 30 Apr 2019 01:32:49 -0700 Message-ID: <5CC8082F.4090903@windriver.com> Date: Tue, 30 Apr 2019 16:32:47 +0800 From: Liwei Song User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Takashi Iwai CC: , Yu Zhao , Mark Brown , Keyon Jie , Jaroslav Kysela , linux-kernel Subject: Re: [PATCH] ALSA: hda: check RIRB to avoid use NULL pointer References: <1556604653-47363-1-git-send-email-liwei.song@windriver.com> In-Reply-To: Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/30/2019 03:31 PM, Takashi Iwai wrote: > On Tue, 30 Apr 2019 08:10:53 +0200, > Song liwei wrote: >> >> From: Liwei Song >> >> Fix the following BUG: >> >> BUG: unable to handle kernel NULL pointer dereference at 000000000000000c >> Workqueue: events azx_probe_work [snd_hda_intel] >> RIP: 0010:snd_hdac_bus_update_rirb+0x80/0x160 [snd_hda_core] >> Call Trace: >> >> azx_interrupt+0x78/0x140 [snd_hda_codec] >> __handle_irq_event_percpu+0x49/0x300 >> handle_irq_event_percpu+0x23/0x60 >> handle_irq_event+0x3c/0x60 >> handle_edge_irq+0xdb/0x180 >> handle_irq+0x23/0x30 >> do_IRQ+0x6a/0x140 >> common_interrupt+0xf/0xf >> >> The Call Trace happened when run kdump on a NFS rootfs system. >> Exist the following calling sequence when boot the second kernel: >> >> azx_first_init() >> --> azx_acquire_irq() >> <-- interrupt come in, azx_interrupt() was called >> --> hda_intel_init_chip() >> --> azx_init_chip() >> --> snd_hdac_bus_init_chip() >> --> snd_hdac_bus_init_cmd_io(); >> --> init rirb.buf and corb.buf >> >> Interrupt happened after azx_acquire_irq() while RIRB still didn't got >> initialized, then NULL pointer will be used when process the interrupt. >> >> Check the value of RIRB to ensure it is not NULL, to aviod some special >> case may hang the system. >> >> Fixes: 14752412721c ("ALSA: hda - Add the controller helper codes to hda-core module") >> Signed-off-by: Liwei Song > > Oh, that's indeed a race there. > > But I guess the check introduced by the patch is still error-prone. > Basically the interrupt handling should be moved after the chip > initialization. I suppose that your platform uses the shared > interrupt, not the MSI? This is the information from /proc/interrupt 134: 0 102 0 0 IR-PCI-MSI 514048-edge snd_hda_intel:card0 > > In anyway, alternative (and likely more certain) fix would be to move > the azx_acquir_irq() call like the patch below (note: totally > untested). Could you check whether it works? Yes, It works. Considering a previous patch like the one you provide will import some issue, so I choose check the invalid value to low the risk, but just as you mentioned, It is not a good solution. commit 542cedec53c9e8b73f3f05bf8468823598c50489 Author: Yu Zhao Date: Tue Sep 11 15:12:46 2018 -0600 Revert "ASoC: Intel: Skylake: Acquire irq after RIRB allocation" This reverts commit 12eeeb4f4733bbc4481d01df35933fc15beb8b19. The patch doesn't fix accessing memory with null pointer in skl_interrupt(). There are two problems: 1) skl_init_chip() is called twice, before and after dma buffer is allocate. The first call sets bus->chip_init which prevents the second from initializing bus->corb.buf and rirb.buf from bus->rb.area. 2) snd_hdac_bus_init_chip() enables interrupt before snd_hdac_bus_init_cmd_io() initializing dma buffers. There is a small window which skl_interrupt() can be called if irq has been acquired. If so, it crashes when using null dma buffer pointers. Thanks, Liwei. > > > thanks, > > Takashi > > > --- a/sound/pci/hda/hda_intel.c > +++ b/sound/pci/hda/hda_intel.c > @@ -1788,9 +1788,6 @@ static int azx_first_init(struct azx *chip) > chip->msi = 0; > } > > - if (azx_acquire_irq(chip, 0) < 0) > - return -EBUSY; > - > pci_set_master(pci); > synchronize_irq(bus->irq); > > @@ -1904,6 +1901,9 @@ static int azx_first_init(struct azx *chip) > return -ENODEV; > } > > + if (azx_acquire_irq(chip, 0) < 0) > + return -EBUSY; > + > strcpy(card->driver, "HDA-Intel"); > strlcpy(card->shortname, driver_short_names[chip->driver_type], > sizeof(card->shortname)); > >