Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp129721pxj; Fri, 7 May 2021 05:24:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPyDAe/jwRQMAjdiyew79Fqjk+Vguk/53SYorjQfqoy7ooVxvbU9FxgdqZK1lCKKn1z4Ln X-Received: by 2002:a17:906:b159:: with SMTP id bt25mr9492585ejb.38.1620390293483; Fri, 07 May 2021 05:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620390293; cv=none; d=google.com; s=arc-20160816; b=u5miPW5xT4hlaBrc8ed4mmj+vNOCfeyPc+ezQGoMsP6tx38CrhuX5RgykgbHzrzWr9 2ekEUF4mX3YFMJs8yl2bP8pY2o/96xWTvteBbowoAoSCLZAYxeJrbXxK+qMHF14DSECy mUGrjPWP/xMb2TcJAY1lv0XTFST69dKyP9v0MSmG75cGO4/qaclzr7dzupxtRTe7qAKP Uu0zhOiCGrfQkRLSv9WeBz4bp8QdKewzaaE8AcoYjFM4u17JlP51g98GPR7b8hh89ot8 ayv6OJN6YSfyFpk52OchE+zqmxxiTv+GdZC8wM9Jqa9szIrmKxchtLZYCmq0rmZExbw9 WxBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:mime-version :dkim-signature; bh=1o9fOfYSfdOLRiAvqZDl7HSV8PVlBtz8PalnoaqHKxE=; b=qoFbdb6qc62qqMsu0dQx+MQYDEAYtmFuUCiIporQiC8ZX04jJk0Up1cXj+fFh2/Jzl 1TON6f1hn/dVe4AtJqrcCSXZ7onPgDIkwUWOWq92nhhN93UOmtzbZsDhbGOEBXU/r09j cx1RBOOLDJUfcdj9Rcx/6bTdet13zH0IUALY/vZN3YIfL1tGee2RXIBkhNJXZ0jm9scW CCgOI+/SWF+UzmmQkjb4eOcdIfjbF/5rTzb4FItfhn01gXAhO5hZ8lFz+e/SqBuCXybW G8/7JbhSwTPs8C/xLk0ZxKbz9+3h9b0Co39x8aqAfydG0P7WI3Mn1insK/TAjE2pvXcb BIUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gse-cs-msu-ru.20150623.gappssmtp.com header.s=20150623 header.b=vwnM0CoC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=msu.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q25si4687102edt.39.2021.05.07.05.24.29; Fri, 07 May 2021 05:24:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gse-cs-msu-ru.20150623.gappssmtp.com header.s=20150623 header.b=vwnM0CoC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=msu.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236045AbhEGJ17 (ORCPT + 99 others); Fri, 7 May 2021 05:27:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236023AbhEGJ16 (ORCPT ); Fri, 7 May 2021 05:27:58 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DF9CC061345 for ; Fri, 7 May 2021 02:18:58 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id v6so10696680ljj.5 for ; Fri, 07 May 2021 02:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gse-cs-msu-ru.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to:cc; bh=1o9fOfYSfdOLRiAvqZDl7HSV8PVlBtz8PalnoaqHKxE=; b=vwnM0CoCg7R1i/1jp1MZvWTP69djgR9Zc5n/8XqqmjmAq0U35kL1RKCMM2kB13+byt OJkErkQuCbfUqm4ME0Oi0poVqXn6xP6BiVhJOQ8wHFIVqjXmBK8We8BNtrBtrzMN/NRm O4ZJ+cpfsQFEAhYoRY76G8UWrNZ4AJ625uSJWXV/HSkbFGEMTfThQ87ox0cj7xeECT/E hnE3OjME6bryymqwRr4aQHtTwbPhzbfv9c9Srbi8vRy+dPxEnPj9vTQ/LqkENWwQCB8R 6jag1InkvRfVl6GfVNzgiRltg8cXOd1ijfH2CJq5BHA1Q6KEJvl2QfSDEinbLjSclnAm Zynw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=1o9fOfYSfdOLRiAvqZDl7HSV8PVlBtz8PalnoaqHKxE=; b=gSuHM/88IFHOTb6J4hvPdHNnvMz/W9Mkjfvask8RMZS8LHLJ2V4yhEuHgNmEwtFSza ZZ5R/BROlWWxAsb5iK6TRfD94+yBcrRzaaVhl0tFP67fDAzFPvUZXFPxexRulG5FuieV 2rWT1+lMllB1F2rO5SQ3whgLEnVkwyklFUDKOc5VhXIlX8fjnczV9ztVJCppXeFnTuKu JCH62p0Tn8CWs3TfgtcPDihrh0CV3tAxuXhOSCxV45NT94tT37RLxqWBWkbl2wmhOXzN daQ3fX+vZHZTs61ir0zzoadQzSKoEvrulPXS9GSFyWXAfqkjc5cNr8Be6SKc+75hyb2S DmRw== X-Gm-Message-State: AOAM530uvirQ9PHU7JAtYZLNqtyVFPaZCJS3j6Wglyvh4qhdtTNhRsT6 +lCodYSUzGrjOJtYqNvAJynVqGt+axF5h1jiNZ0lJg== X-Received: by 2002:a2e:1516:: with SMTP id s22mr7040859ljd.109.1620379137191; Fri, 07 May 2021 02:18:57 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:7e06:0:0:0:0:0 with HTTP; Fri, 7 May 2021 02:18:56 -0700 (PDT) From: =?UTF-8?B?0J/QvtC00LPQvtGA0L3Ri9C5INCQ0LvQtdC60YHQtdC5INCe0LvQtdCz0L7QstC40Yc=?= Date: Fri, 7 May 2021 12:18:56 +0300 Message-ID: Subject: [BUG] ALSA: korg1212: Potential NULL pointer dereference in snd_korg1212_interrupt() To: Jaroslav Kysela , Takashi Iwai , Leon Romanovsky , Pierre-Louis Bossart Cc: Alexey Khoroshilov , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org snd_korg1212_create() makes the following steps during initialization of the card: 1) registers an interrupt handler (lines 2230-2232) 2) allocates and initializes korg1212->sharedBufferPtr (lines 2280-2287) 3) reboots the card via snd_korg1212_Send1212Command() (line 2358) 2145 static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, struct snd_korg1212 **rchip) 2147 { ... 2230 err = request_irq(pci->irq, snd_korg1212_interrupt, 2231 IRQF_SHARED, 2232 KBUILD_MODNAME, korg1212); ... 2280 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, 2281 sizeof(struct KorgSharedBuffer), &korg1212->dma_shared) < 0){ 2282 snd_printk(KERN_ERR "korg1212: can not allocate shared buffer memory (%zdbytes)\n", sizeof(struct KorgSharedBuffer)); 2283 snd_korg1212_free(korg1212); 2284 return -ENOMEM; 2285 } 2286 korg1212->sharedBufferPtr = (struct KorgSharedBuffer*)korg1212->dma_shared.area; 2287 korg1212->sharedBufferPhy = korg1212->dma_shared.addr; ... 2358 rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_RebootCard, 0, 0, 0, 0); ... 2412 } But if interrupt happens when snd_korg1212_create() is still within lines 2233-2286, snd_korg1212_interrupt() may dereference korg1212->sharedBufferPtr before it was initialized without any checks (line 1149): 1098 static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id) 1099 { ... 1116 switch (doorbellValue) { ... 1145 case K1212_DB_CARDSTOPPED: 1146 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n", 1147 korg1212->irqcount, doorbellValue, 1148 stateName[korg1212->cardState]); 1149 korg1212->sharedBufferPtr->cardCommand = 0; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1150 break; ... 1185 } Should we be sure that such interrupt cannot happen or should we move the registration of the interrupt handler after korg1212->sharedBufferPtr is initialized? Found by Linux Driver Verification project (linuxtesting.org).