From patchwork Tue Mar 28 08:56:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Reshetova, Elena" X-Patchwork-Id: 9648441 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 D1602601E9 for ; Tue, 28 Mar 2017 08:59:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3B5C26E64 for ; Tue, 28 Mar 2017 08:59:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B760327E5A; Tue, 28 Mar 2017 08:59:48 +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=-1.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_SORBS_SPAM autolearn=no 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 9FFBF26E64 for ; Tue, 28 Mar 2017 08:59:47 +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=4Od3Nmle5ubJAqFST0aCs7OUwBnBjuhD71Upx59/uwo=; b=QS6ah3n9AhktEkHw/oosx1Ezec rfwfZ/EkrnU8rX8H7rgXiYqYPkvYGixbFvXFPdb5FnUvmCnx6+LUII9cZa1bOaLTqONf/jYZX+iDn V/KE/q0+KcCt1eiULAV1aCje9ZFVNBLuTRqiBlXaoxZfHuDqo5ohuvAPVnIbMDUBd/t1YUJXMxA2z nUE3u34X/BECR3kSYVY2NEBJOiOmauORJqu7uHgX0YOwAxeYZi23y4BVpI/u+8N6h8VmZNt11PTr9 Qzq+F5W4zCPVpWFtMrCDJ3gBpfnQcmSqoy312iUhwjPFOXRRoXXTUxenks1CJomie3PHnDxVK3YLh QQsREhVw==; 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 1csmyg-0002Rh-K9; Tue, 28 Mar 2017 08:59:46 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1csmxm-0001YO-55 for linux-arm-kernel@bombadil.infradead.org; Tue, 28 Mar 2017 08:58:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=S5KDn32+UWEyipQ7E2AYTRjOXgbRiTBKPloWwpKx5Hs=; b=H24YaTU9lSA/LH1Qhdmx+jKLu oxaM8Kojx5EySbV0GQXNDGZgnpc8++cKzLwu3cdN95Aj0ecNRTNeRadbL7+UNdMFBq9J9G+NaPmRT 6V7p9YH6hJIqNx1Ytev76vOWdp6GpXaViY1Prktun9lcNtICDlghKm28rs+OlxL0xGIBolXlBA1wm eNifzDWLzXm0TikJFoTvy3E37LNaqeEgutLNwwTqFkwXD1ruu+S/GS3GwfinurlX9PW5ZKLDoeERI KyfGQ5DhVuBWf5rhKSFyl4dHHhFDr0N+VllWLGsHUQc2uPL9ifEBfYxXmIRBEHDJVvsUvl8q8L456 Mt9cU3IPw==; Received: from mga02.intel.com ([134.134.136.20]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1csmxh-0002KR-Tk for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2017 08:58:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490691525; x=1522227525; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=IOnLsyIUPg6lwyz51M82kIMQyiyGLjJkE4EiL3zNfl4=; b=SERgPUB1P/jioQylXa7EmRcPhdie+hqjibjw5erXgE+jlOAw2jpEQTeq 0bxg2hCRlJsauFzEKUoNB9ApNVAU/A==; Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2017 01:58:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,236,1486454400"; d="scan'208";a="81798243" Received: from unknown (HELO elena-ThinkPad-X230.ger.corp.intel.com) ([10.249.44.56]) by fmsmga006.fm.intel.com with ESMTP; 28 Mar 2017 01:58:16 -0700 From: Elena Reshetova To: netdev@vger.kernel.org Subject: [PATCH 13/16] drivers, net, ppp: convert ppp_file.refcnt from atomic_t to refcount_t Date: Tue, 28 Mar 2017 11:56:40 +0300 Message-Id: <1490691403-4016-14-git-send-email-elena.reshetova@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490691403-4016-1-git-send-email-elena.reshetova@intel.com> References: <1490691403-4016-1-git-send-email-elena.reshetova@intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170328_095846_250523_B68D7F67 X-CRM114-Status: GOOD ( 16.62 ) 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, Elena Reshetova , nbd@openwrt.org, linux-rdma@vger.kernel.org, saeedm@mellanox.com, ganeshgr@chelsio.com, Hans Liljestrand , David Windsor , keescook@chromium.org, j@w1.fi, ajk@comnets.uni-bremen.de, leonro@mellanox.com, matthias.bgg@gmail.com, linux-hams@vger.kernel.org, kvalo@codeaurora.org, blogic@openwrt.org, linux-arm-kernel@lists.infradead.org, linux-ppp@vger.kernel.org, yishaih@mellanox.com, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org 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 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 --- drivers/net/ppp/ppp_generic.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index f9c0e62..7b1352c 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -84,7 +85,7 @@ struct ppp_file { struct sk_buff_head xq; /* pppd transmit queue */ struct sk_buff_head rq; /* receive queue for pppd */ wait_queue_head_t rwait; /* for poll on reading /dev/ppp */ - atomic_t refcnt; /* # refs (incl /dev/ppp attached) */ + refcount_t refcnt; /* # refs (incl /dev/ppp attached) */ int hdrlen; /* space to leave for headers */ int index; /* interface unit / channel number */ int dead; /* unit/channel has been shut down */ @@ -407,7 +408,7 @@ static int ppp_release(struct inode *unused, struct file *file) unregister_netdevice(ppp->dev); rtnl_unlock(); } - if (atomic_dec_and_test(&pf->refcnt)) { + if (refcount_dec_and_test(&pf->refcnt)) { switch (pf->kind) { case INTERFACE: ppp_destroy_interface(PF_TO_PPP(pf)); @@ -880,7 +881,7 @@ static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf, mutex_lock(&pn->all_ppp_mutex); ppp = ppp_find_unit(pn, unit); if (ppp) { - atomic_inc(&ppp->file.refcnt); + refcount_inc(&ppp->file.refcnt); file->private_data = &ppp->file; err = 0; } @@ -895,7 +896,7 @@ static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf, spin_lock_bh(&pn->all_channels_lock); chan = ppp_find_channel(pn, unit); if (chan) { - atomic_inc(&chan->file.refcnt); + refcount_inc(&chan->file.refcnt); file->private_data = &chan->file; err = 0; } @@ -2641,7 +2642,7 @@ ppp_unregister_channel(struct ppp_channel *chan) pch->file.dead = 1; wake_up_interruptible(&pch->file.rwait); - if (atomic_dec_and_test(&pch->file.refcnt)) + if (refcount_dec_and_test(&pch->file.refcnt)) ppp_destroy_channel(pch); } @@ -3011,7 +3012,7 @@ init_ppp_file(struct ppp_file *pf, int kind) pf->kind = kind; skb_queue_head_init(&pf->xq); skb_queue_head_init(&pf->rq); - atomic_set(&pf->refcnt, 1); + refcount_set(&pf->refcnt, 1); init_waitqueue_head(&pf->rwait); } @@ -3128,7 +3129,7 @@ ppp_connect_channel(struct channel *pch, int unit) list_add_tail(&pch->clist, &ppp->channels); ++ppp->n_channels; pch->ppp = ppp; - atomic_inc(&ppp->file.refcnt); + refcount_inc(&ppp->file.refcnt); ppp_unlock(ppp); ret = 0; @@ -3159,7 +3160,7 @@ ppp_disconnect_channel(struct channel *pch) if (--ppp->n_channels == 0) wake_up_interruptible(&ppp->file.rwait); ppp_unlock(ppp); - if (atomic_dec_and_test(&ppp->file.refcnt)) + if (refcount_dec_and_test(&ppp->file.refcnt)) ppp_destroy_interface(ppp); err = 0; }