From patchwork Fri Oct 20 07:23:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Reshetova, Elena" X-Patchwork-Id: 10019051 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 E3161602CB for ; Fri, 20 Oct 2017 07:28:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3F5728ECE for ; Fri, 20 Oct 2017 07:28:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C762A28ED2; Fri, 20 Oct 2017 07:28:10 +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=-3.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6A3A628ECE for ; Fri, 20 Oct 2017 07:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=l0I8zBQm9oM1516EwZ6LoRmRya7VDTQPjXXsbW5kKik=; b=AuDx1BdtPkS8y5lG+Ea84sye9u o2sKAgUbqrAVeyKeYpIlinzoGet5CessCH5mZIrdg0z2xjdBlCF3hNVUScAZ6P0nieshzkGJJPamT 774WdrSSX+xIed9miElx/UimJ5UYi3Pw4swjDsrbNao7CGz3euF/ZJIpv/8d1QLh4DV1i7PYntK3q OYmtC+x9caLWDw2tFUXYb887mwIYTOiKnvGpzm2S9ayoT0mgKHZkD3lLTisXxeA8fsMWz47n0mtTm ej24OybR4GlReBaW5iPmZvZSlab2eox9NDz6ubAU7Yw49yWuZ+s22a3guX5h/UTBvFd8JREI+GCDT MHDFhDpw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e5Rir-0000Tm-Ux; Fri, 20 Oct 2017 07:28:01 +0000 Received: from mga07.intel.com ([134.134.136.100]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e5Rh5-0007F8-CC; Fri, 20 Oct 2017 07:26:29 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP; 20 Oct 2017 00:25:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,405,1503385200"; d="scan'208";a="911831133" Received: from elena-thinkpad-x230.fi.intel.com ([10.237.72.87]) by FMSMGA003.fm.intel.com with ESMTP; 20 Oct 2017 00:25:15 -0700 From: Elena Reshetova To: davem@davemloft.net Subject: [PATCH 14/15] drivers, net, ppp: convert syncppp.refcnt from atomic_t to refcount_t Date: Fri, 20 Oct 2017 10:23:48 +0300 Message-Id: <1508484229-19706-15-git-send-email-elena.reshetova@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508484229-19706-1-git-send-email-elena.reshetova@intel.com> References: <1508484229-19706-1-git-send-email-elena.reshetova@intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171020_002611_813967_3AEBD929 X-CRM114-Status: GOOD ( 10.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterz@infradead.org, matanb@mellanox.com, paulus@samba.org, zbr@ioremap.net, Elena Reshetova , nbd@openwrt.org, linux-rdma@vger.kernel.org, saeedm@mellanox.com, ganeshgr@chelsio.com, ajk@comnets.uni-bremen.de, keescook@chromium.org, sean.wang@mediatek.com, leonro@mellanox.com, linux-mediatek@lists.infradead.org, john@phrozen.org, matthias.bgg@gmail.com, linux-hams@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, yishaih@mellanox.com, linux-kernel@vger.kernel.org, linux-ppp@vger.kernel.org, tariqt@mellanox.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP atomic_t variables are currently used to implement reference counters with the following properties: - counter is initialized to 1 using atomic_set() - a resource is freed upon counter reaching zero - once counter reaches zero, its further increments aren't allowed - counter schema uses basic atomic operations (set, inc, inc_not_zero, dec_and_test, etc.) Such atomic variables should be converted to a newly provided refcount_t type and API that prevents accidental counter overflows and underflows. This is important since overflows and underflows can lead to use-after-free situation and be exploitable. The variable syncppp.refcnt is used as pure reference counter. Convert it to refcount_t and fix up the operations. Suggested-by: Kees Cook Reviewed-by: David Windsor Reviewed-by: Hans Liljestrand Signed-off-by: Elena Reshetova --- drivers/net/ppp/ppp_synctty.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c index 7868c29..7196f00 100644 --- a/drivers/net/ppp/ppp_synctty.c +++ b/drivers/net/ppp/ppp_synctty.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -72,7 +73,7 @@ struct syncppp { struct tasklet_struct tsk; - atomic_t refcnt; + refcount_t refcnt; struct completion dead_cmp; struct ppp_channel chan; /* interface to generic ppp layer */ }; @@ -141,14 +142,14 @@ static struct syncppp *sp_get(struct tty_struct *tty) read_lock(&disc_data_lock); ap = tty->disc_data; if (ap != NULL) - atomic_inc(&ap->refcnt); + refcount_inc(&ap->refcnt); read_unlock(&disc_data_lock); return ap; } static void sp_put(struct syncppp *ap) { - if (atomic_dec_and_test(&ap->refcnt)) + if (refcount_dec_and_test(&ap->refcnt)) complete(&ap->dead_cmp); } @@ -182,7 +183,7 @@ ppp_sync_open(struct tty_struct *tty) skb_queue_head_init(&ap->rqueue); tasklet_init(&ap->tsk, ppp_sync_process, (unsigned long) ap); - atomic_set(&ap->refcnt, 1); + refcount_set(&ap->refcnt, 1); init_completion(&ap->dead_cmp); ap->chan.private = ap; @@ -232,7 +233,7 @@ ppp_sync_close(struct tty_struct *tty) * our channel ops (i.e. ppp_sync_send/ioctl) are in progress * by the time it returns. */ - if (!atomic_dec_and_test(&ap->refcnt)) + if (!refcount_dec_and_test(&ap->refcnt)) wait_for_completion(&ap->dead_cmp); tasklet_kill(&ap->tsk);