From patchwork Mon Feb 20 11:38:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Reshetova, Elena" X-Patchwork-Id: 9582647 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 7BAB2604A0 for ; Mon, 20 Feb 2017 11:43:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C54928803 for ; Mon, 20 Feb 2017 11:43:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F65C2880A; Mon, 20 Feb 2017 11:43:49 +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 D1F4B28803 for ; Mon, 20 Feb 2017 11:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753048AbdBTLnR (ORCPT ); Mon, 20 Feb 2017 06:43:17 -0500 Received: from mga03.intel.com ([134.134.136.65]:6903 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752871AbdBTLnG (ORCPT ); Mon, 20 Feb 2017 06:43:06 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Feb 2017 03:43:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,186,1484035200"; d="scan'208";a="50236629" Received: from elena-thinkpad-x230.fi.intel.com ([10.237.72.69]) by orsmga002.jf.intel.com with ESMTP; 20 Feb 2017 03:43:02 -0800 From: Elena Reshetova To: linux-security-module@vger.kernel.org Cc: keyrings@vger.kernel.org, peterz@infradead.org, gregkh@linuxfoundation.org, james.l.morris@oracle.com, dhowells@redhat.com, takedakn@nttdata.co.jp, penguin-kernel@I-love.SAKURA.ne.jp, Elena Reshetova , Hans Liljestrand , Kees Cook , David Windsor Subject: [PATCH 3/3] security, tomoyo: convert tomoyo_query_observers from atomic_t to refcount_t Date: Mon, 20 Feb 2017 13:38:50 +0200 Message-Id: <1487590730-18352-4-git-send-email-elena.reshetova@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487590730-18352-1-git-send-email-elena.reshetova@intel.com> References: <1487590730-18352-1-git-send-email-elena.reshetova@intel.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP refcount_t type and corresponding API should be used instead of atomic_t when the variable is used as a reference counter. This allows to avoid accidental refcounter overflows that might lead to use-after-free situations. Signed-off-by: Elena Reshetova Signed-off-by: Hans Liljestrand Signed-off-by: Kees Cook Signed-off-by: David Windsor --- security/tomoyo/common.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c index e0fb750..9a7605a 100644 --- a/security/tomoyo/common.c +++ b/security/tomoyo/common.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "common.h" /* String table for operation mode. */ @@ -1907,7 +1908,7 @@ static DEFINE_SPINLOCK(tomoyo_query_list_lock); * Number of "struct file" referring /sys/kernel/security/tomoyo/query * interface. */ -static atomic_t tomoyo_query_observers = ATOMIC_INIT(0); +static refcount_t tomoyo_query_observers = REFCOUNT_INIT(0); /** * tomoyo_truncate - Truncate a line. @@ -2015,7 +2016,7 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) switch (r->mode) { case TOMOYO_CONFIG_ENFORCING: error = -EPERM; - if (atomic_read(&tomoyo_query_observers)) + if (refcount_read(&tomoyo_query_observers)) break; goto out; case TOMOYO_CONFIG_LEARNING: @@ -2059,7 +2060,7 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) wake_up_all(&tomoyo_query_wait); if (wait_event_interruptible_timeout (tomoyo_answer_wait, entry.answer || - !atomic_read(&tomoyo_query_observers), HZ)) + !refcount_read(&tomoyo_query_observers), HZ)) break; else entry.timer++; @@ -2437,7 +2438,7 @@ int tomoyo_open_control(const u8 type, struct file *file) * there is some process monitoring /sys/kernel/security/tomoyo/query. */ if (type == TOMOYO_QUERY) - atomic_inc(&tomoyo_query_observers); + refcount_inc(&tomoyo_query_observers); file->private_data = head; tomoyo_notify_gc(head, true); return 0; @@ -2687,7 +2688,7 @@ void tomoyo_close_control(struct tomoyo_io_buffer *head) * observer counter. */ if (head->type == TOMOYO_QUERY && - atomic_dec_and_test(&tomoyo_query_observers)) + refcount_dec_and_test(&tomoyo_query_observers)) wake_up_all(&tomoyo_answer_wait); tomoyo_notify_gc(head, false); }