From patchwork Wed Nov 23 05:16:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Goel X-Patchwork-Id: 9442635 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 201CF600BA for ; Wed, 23 Nov 2016 05:21:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FF7020410 for ; Wed, 23 Nov 2016 05:21:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 015C6204BD; Wed, 23 Nov 2016 05:21:27 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 CB63E20410 for ; Wed, 23 Nov 2016 05:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750799AbcKWFVX (ORCPT ); Wed, 23 Nov 2016 00:21:23 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:44108 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750710AbcKWFVW (ORCPT ); Wed, 23 Nov 2016 00:21:22 -0500 Received: from epcpsbgm2new.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OH2014QGXJFQR20@mailout4.samsung.com> for linux-security-module@vger.kernel.org; Wed, 23 Nov 2016 14:21:20 +0900 (KST) X-AuditID: cbfee61b-f796f6d000004092-d1-58352750e9ea Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 33.31.16530.05725385; Wed, 23 Nov 2016 14:21:20 +0900 (KST) Received: from localhost.localdomain ([107.108.92.210]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OH200MSBXJFBTC0@mmp2.samsung.com>; Wed, 23 Nov 2016 14:21:20 +0900 (KST) From: Vishal Goel To: casey@schaufler-ca.com, linux-security-module@vger.kernel.org Cc: vishal.goel@samsung.com, himanshu.sh@samsung.com, Vishal Goel , Himanshu Shukla Subject: [PATCH] SMACK: Add new lock for adding entry in smack master list Date: Wed, 23 Nov 2016 10:46:57 +0530 Message-id: <1479878217-20022-1-git-send-email-vishal.goel@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFLMWRmVeSWpSXmKPExsVy+t9jQd0AddMIgxmnzC3ubfvFZrH3SQur xYeeR2wW626fZnRg8ejbsorR4+j+RWwenzfJBTBHudlkpCampBYppOYl56dk5qXbKoWGuOla KCnkJeam2ipF6PqGBCkplCXmlAJ5RgZowME5wD1YSd8uwS2j/ZVrwRreisXTvrA1MH7n6mLk 5JAQMJGYNfsYO4QtJnHh3no2EFtIYBajxLYbAV2MXED2T0aJ3TvuM4Ik2AS0JXrn3WUCsUUE HCUaTy1nAiliFuhilDg7rZO1i5GDQ1jAS6J9hz1IDYuAqsSv9vvMIDavgLtE2+UOJohlchIn j01mncDIvYCRYRWjRGpBckFxUnquUV5quV5xYm5xaV66XnJ+7iZGcLg9k97BeHiX+yFGAQ5G JR5ejS0mEUKsiWXFlbmHGCU4mJVEeGPlTCOEeFMSK6tSi/Lji0pzUosPMZoCHTCRWUo0OR8Y C3kl8YYm5ibmxgYW5paWJkZK4ryNs5+FCwmkJ5akZqemFqQWwfQxcXBKNTDOL+058WtPXuwk ZQ21n64Lso97hqd+WLOiylmG5cLUvG+Gf7jPLDlbkrHFzOSN6ILJznu+brYpm5VYM5+5YMby dU+S24Xmqsxc8/flBPHPTkKr5Nl6X/mcyHj1Ich39X6ZqvpYidy1U0Qcmqr3uLWwLX919JOP 85LDFUuqLnjOFLg74YXYkopwJZbijERDLeai4kQA5Xup/U0CAAA= X-MTR: 20000000000000000@CPGS Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP "smk_set_access()" function adds a new rule entry in subject label specific list(rule_list) and in global rule list(smack_rule_list) both. Mutex lock (rule_lock) is used to avoid simultaneous updates. But this lock is subject label specific lock. If 2 processes tries to add different rules(i.e with different subject labels) simultaneously, then both the processes can take the "rule_lock" respectively. So it will cause a problem while adding entries in master rule list. Now a new mutex lock(smack_master_list_lock) has been taken to add entry in smack_rule_list to avoid simultaneous updates of different rules. Signed-off-by: Vishal Goel Signed-off-by: Himanshu Shukla Acked-by: Casey Schaufler --- security/smack/smackfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index 6492fe9..0d7294f 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -67,6 +67,7 @@ enum smk_inos { /* * List locks */ +static DEFINE_MUTEX(smack_master_list_lock); static DEFINE_MUTEX(smack_cipso_lock); static DEFINE_MUTEX(smack_ambient_lock); static DEFINE_MUTEX(smk_net4addr_lock); @@ -262,12 +263,16 @@ static int smk_set_access(struct smack_parsed_rule *srp, * it needs to get added for reporting. */ if (global) { + mutex_unlock(rule_lock); smlp = kzalloc(sizeof(*smlp), GFP_KERNEL); if (smlp != NULL) { smlp->smk_rule = sp; + mutex_lock(&smack_master_list_lock); list_add_rcu(&smlp->list, &smack_rule_list); + mutex_unlock(&smack_master_list_lock); } else rc = -ENOMEM; + return rc; } }