From patchwork Wed Mar 2 02:47:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "majun (F)" X-Patchwork-Id: 8477831 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BC07A9F2F0 for ; Wed, 2 Mar 2016 02:53:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D7EE920382 for ; Wed, 2 Mar 2016 02:53:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E893120364 for ; Wed, 2 Mar 2016 02:53:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aawt7-0007Sj-MU; Wed, 02 Mar 2016 02:51:45 +0000 Received: from szxga03-in.huawei.com ([119.145.14.66]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aawt3-0007G1-Li for linux-arm-kernel@lists.infradead.org; Wed, 02 Mar 2016 02:51:42 +0000 Received: from 172.24.1.51 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.51]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BXA74206; Wed, 02 Mar 2016 10:48:11 +0800 (CST) Received: from localhost (10.177.235.245) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Wed, 2 Mar 2016 10:48:03 +0800 From: MaJun To: , , , , , , , , , , Subject: [PATCH] Change the spin_lock/unlock_irq interface in proc_alloc_inum() function Date: Wed, 2 Mar 2016 10:47:59 +0800 Message-ID: <1456886879-28128-1-git-send-email-majun258@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.177.235.245] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.56D65470.0072, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: e5455d5ecedcfff138d64c06edda8321 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160301_185142_003104_0BCBA28D X-CRM114-Status: UNSURE ( 7.71 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.2 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ma Jun The spin_lock/unlock_irq interface is not safe when this function is called at some case which need irq disabled. For example: spin_lock_irqsave() | request_irq() --> proc_alloc_inum() | spin_unlock_irqrestore() Reported-by: Fan Jinke Signed-off-by: Ma Jun --- fs/proc/generic.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index ff3ffc7..4fc1502 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -191,23 +191,24 @@ int proc_alloc_inum(unsigned int *inum) { unsigned int i; int error; + unsigned long flags; retry: if (!ida_pre_get(&proc_inum_ida, GFP_KERNEL)) return -ENOMEM; - spin_lock_irq(&proc_inum_lock); + spin_lock_irqsave(&proc_inum_lock, flags); error = ida_get_new(&proc_inum_ida, &i); - spin_unlock_irq(&proc_inum_lock); + spin_unlock_irqrestore(&proc_inum_lock, flags); if (error == -EAGAIN) goto retry; else if (error) return error; if (i > UINT_MAX - PROC_DYNAMIC_FIRST) { - spin_lock_irq(&proc_inum_lock); + spin_lock_irqsave(&proc_inum_lock, flags); ida_remove(&proc_inum_ida, i); - spin_unlock_irq(&proc_inum_lock); + spin_unlock_irqrestore(&proc_inum_lock, flags); return -ENOSPC; } *inum = PROC_DYNAMIC_FIRST + i;