From patchwork Fri May 1 13:21:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 226669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B008C47253 for ; Fri, 1 May 2020 13:31:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B4F4208DB for ; Fri, 1 May 2020 13:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339919; bh=1bJXgS9EGSsKXLluKrL63N6r/YnFN67KmUdN1uqhg/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=yYZ4D/pjOWL4ZsBSpGdkOvW+gLDBWIXNqfsgilKahtNs+KSaT2MMXMcmPXj9BMxR8 smQBtZIfZsWDKokIlCK8+zyohwNQuDF7oD0ajxny0nebO3wL6NYo4tZwPknNvM1z0e jvzK3h9qTdTtxPa5dj3c2DooSM4ZDUMtIfGHsj68= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729646AbgEANb4 (ORCPT ); Fri, 1 May 2020 09:31:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:56622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730215AbgEANbx (ORCPT ); Fri, 1 May 2020 09:31:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EBD2D208C3; Fri, 1 May 2020 13:31:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339913; bh=1bJXgS9EGSsKXLluKrL63N6r/YnFN67KmUdN1uqhg/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NI7ZMeBXhuHMBWAKgW4yR7Hu//KbkYt+v4giVkOFLWS5gI5vXY6oD/Kwa8ZqpxTI3 QRNIGBgtysz/uKlncl/ZzcSRUoZabMvN09xp3TizoHkH+Qo0LnXPbzVMDo1ZIgk6ft 2CZjDW+jHoJB3LE9uOvLPkVEPpK+d1YwpDoosI5Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiyu Yang , Xin Tan , "David S. Miller" Subject: [PATCH 4.14 030/117] net/x25: Fix x25_neigh refcnt leak when receiving frame Date: Fri, 1 May 2020 15:21:06 +0200 Message-Id: <20200501131548.437101101@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501131544.291247695@linuxfoundation.org> References: <20200501131544.291247695@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xiyu Yang [ Upstream commit f35d12971b4d814cdb2f659d76b42f0c545270b6 ] x25_lapb_receive_frame() invokes x25_get_neigh(), which returns a reference of the specified x25_neigh object to "nb" with increased refcnt. When x25_lapb_receive_frame() returns, local variable "nb" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one path of x25_lapb_receive_frame(). When pskb_may_pull() returns false, the function forgets to decrease the refcnt increased by x25_get_neigh(), causing a refcnt leak. Fix this issue by calling x25_neigh_put() when pskb_may_pull() returns false. Fixes: cb101ed2c3c7 ("x25: Handle undersized/fragmented skbs") Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/x25/x25_dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/net/x25/x25_dev.c +++ b/net/x25/x25_dev.c @@ -120,8 +120,10 @@ int x25_lapb_receive_frame(struct sk_buf goto drop; } - if (!pskb_may_pull(skb, 1)) + if (!pskb_may_pull(skb, 1)) { + x25_neigh_put(nb); return 0; + } switch (skb->data[0]) {