From patchwork Wed Mar 1 09:58:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Reshetova, Elena" X-Patchwork-Id: 9598013 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 6B4ED60429 for ; Wed, 1 Mar 2017 10:04:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D2AE28532 for ; Wed, 1 Mar 2017 10:04:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FBBD2853C; Wed, 1 Mar 2017 10:04:22 +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.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 7A3B528532 for ; Wed, 1 Mar 2017 10:04:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751102AbdCAKEB (ORCPT ); Wed, 1 Mar 2017 05:04:01 -0500 Received: from mga09.intel.com ([134.134.136.24]:6155 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750709AbdCAKDq (ORCPT ); Wed, 1 Mar 2017 05:03:46 -0500 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Mar 2017 01:58:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,224,1484035200"; d="scan'208";a="230977062" Received: from elena-thinkpad-x230.fi.intel.com ([10.237.72.69]) by fmsmga004.fm.intel.com with ESMTP; 01 Mar 2017 01:58:11 -0800 From: Elena Reshetova To: linux-kernel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, peterz@infradead.org, gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, petr@vandrovec.name, Elena Reshetova , Hans Liljestrand , Kees Cook , David Windsor Subject: [PATCH] fs, ncpfs: convert ncp_request_reply.refs from atomic_t to refcount_t Date: Wed, 1 Mar 2017 11:58:04 +0200 Message-Id: <1488362284-3385-1-git-send-email-elena.reshetova@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 --- fs/ncpfs/sock.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ncpfs/sock.c b/fs/ncpfs/sock.c index 4bfeae2..c9d5012 100644 --- a/fs/ncpfs/sock.c +++ b/fs/ncpfs/sock.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "ncp_fs.h" @@ -51,7 +52,7 @@ static int _send(struct socket *sock, const void *buff, int len) struct ncp_request_reply { struct list_head req; wait_queue_head_t wq; - atomic_t refs; + refcount_t refs; unsigned char* reply_buf; size_t datalen; int result; @@ -71,7 +72,7 @@ static inline struct ncp_request_reply* ncp_alloc_req(void) return NULL; init_waitqueue_head(&req->wq); - atomic_set(&req->refs, (1)); + refcount_set(&req->refs, (1)); req->status = RQ_IDLE; return req; @@ -79,12 +80,12 @@ static inline struct ncp_request_reply* ncp_alloc_req(void) static void ncp_req_get(struct ncp_request_reply *req) { - atomic_inc(&req->refs); + refcount_inc(&req->refs); } static void ncp_req_put(struct ncp_request_reply *req) { - if (atomic_dec_and_test(&req->refs)) + if (refcount_dec_and_test(&req->refs)) kfree(req); }