From patchwork Thu Jun 1 07:17:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 9758789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3318660375 for ; Thu, 1 Jun 2017 07:16:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25020284C3 for ; Thu, 1 Jun 2017 07:16:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19E6B284FE; Thu, 1 Jun 2017 07:16:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D55BC284C3 for ; Thu, 1 Jun 2017 07:16:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751346AbdFAHP7 (ORCPT ); Thu, 1 Jun 2017 03:15:59 -0400 Received: from m12-12.163.com ([220.181.12.12]:39204 "EHLO m12-12.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751091AbdFAHP6 (ORCPT ); Thu, 1 Jun 2017 03:15:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=23XlYRGAzvgnPfdqmr yTFy0BudYMRhshrrCLoJ2aMmQ=; b=cRhoDvKgifqTXiAuUamWVLuIqvIhRTvwFP qSYQywJlXqDFORwyV3xxkIwSPVrCJdGAyiHFzrJoc8q2fI98Jgugm6NAKfAUZBqr AbnossYJ45LF+5wtO2FxpszXUXNHnFHHJBH52VYBoQ95ifYpJm6SOwX7nu8SoScV okgaywq1s= Received: from bai-oslab.tsinghua.edu.cn (unknown [166.111.70.19]) by smtp8 (Coremail) with SMTP id DMCowAB3fh4Yvy9ZnsRSHg--.24711S2; Thu, 01 Jun 2017 15:15:40 +0800 (CST) From: Jia-Ju Bai To: awalls@md.metrocast.net, mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] cx18: Fix a sleep-in-atomic bug in snd_cx18_pcm_hw_free Date: Thu, 1 Jun 2017 15:17:51 +0800 Message-Id: <1496301472-2754-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: DMCowAB3fh4Yvy9ZnsRSHg--.24711S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZFy8Zw4Utr4kGr4kXr4kXrb_yoW8GrykpF WUtryFkrZ0qF1qqrn0yan5ZF1rCan3K34UKFW293srZF4fXa43JF1jyryUZFWYvr4kZanx JFy5Jr9xGFyDAFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UHWl9UUUUU= X-Originating-IP: [166.111.70.19] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbiHhzpelSIVWUEFwAAsu Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver may sleep under a spin lock, and the function call path is: snd_cx18_pcm_hw_free (acquire the lock by spin_lock_irqsave) vfree --> may sleep To fix it, the "substream->runtime->dma_area" is passed to a temporary value, and mark it NULL when holding the lock. The memory is freed by vfree through the temporary value outside the lock holding. Signed-off-by: Jia-Ju Bai --- drivers/media/pci/cx18/cx18-alsa-pcm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/media/pci/cx18/cx18-alsa-pcm.c b/drivers/media/pci/cx18/cx18-alsa-pcm.c index 205a98d..8c51e4c 100644 --- a/drivers/media/pci/cx18/cx18-alsa-pcm.c +++ b/drivers/media/pci/cx18/cx18-alsa-pcm.c @@ -257,14 +257,17 @@ static int snd_cx18_pcm_hw_free(struct snd_pcm_substream *substream) { struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream); unsigned long flags; + unsigned char *dma_area = NULL; spin_lock_irqsave(&cxsc->slock, flags); if (substream->runtime->dma_area) { dprintk("freeing pcm capture region\n"); - vfree(substream->runtime->dma_area); + dma_area = substream->runtime->dma_area; substream->runtime->dma_area = NULL; } spin_unlock_irqrestore(&cxsc->slock, flags); + if (dma_area) + vfree(dma_area); return 0; }