From mboxrd@z Thu Jan 1 00:00:00 1970 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,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 245FCC43331 for ; Mon, 11 Nov 2019 18:42:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EFA46214E0 for ; Mon, 11 Nov 2019 18:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497755; bh=HnFFDYxUvaBTgrEftAE9AwROrLlOKZdZoREsjO6/fcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jMOMCirwcYZsYyr2xZ1vci4cgSY0qdEIzN+XuIOPO1Oq2xTfqrr2sZ4CWL++admqB cnX1sYqWJtcKRjy3L7hi4irGOvQzu0sagPwXL1yVpBjsCXDmFDXNNtOZY5Jxlpb8AU V6h3Tp0wCVlTC8HgfzslgHLwZQ++An3mFsl44T5o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729535AbfKKSmd (ORCPT ); Mon, 11 Nov 2019 13:42:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:33710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729094AbfKKSma (ORCPT ); Mon, 11 Nov 2019 13:42:30 -0500 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 5A851214E0; Mon, 11 Nov 2019 18:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497749; bh=HnFFDYxUvaBTgrEftAE9AwROrLlOKZdZoREsjO6/fcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0upq1lLj/s/j5Fq0dVpLqmZ6AUOzHbA24uHmisp95Bd999ReGmyYT8DmrKCx+vP2N jiDJ5xahqL+Z2LzxqiYj0il9EP/o2KOLGDHeIWrHtqQuV4cmk9m1+4M4OnnBypt2z2 cAId7F54J8e81MDCNU5yfk8HCjZaXWeQSM1dW68E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= , Marc Kleine-Budde Subject: [PATCH 4.19 047/125] can: rx-offload: can_rx_offload_queue_sorted(): fix error handling, avoid skb mem leak Date: Mon, 11 Nov 2019 19:28:06 +0100 Message-Id: <20191111181446.589841056@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Kleine-Budde commit ca913f1ac024559ebc17f0b599af262f0ad997c9 upstream. If the rx-offload skb_queue is full can_rx_offload_queue_sorted() will not queue the skb and return with an error. None of the callers of this function, issue a kfree_skb() to free the not queued skb. This results in a memory leak. This patch fixes the problem by freeing the skb in case of a full queue. The return value is adjusted to -ENOBUFS to better reflect the actual problem. The device stats handling is left to the callers, as this function might be used in both the rx and tx path. Fixes: 55059f2b7f86 ("can: rx-offload: introduce can_rx_offload_get_echo_skb() and can_rx_offload_queue_sorted() functions") Cc: linux-stable Cc: Martin Hundebøll Reported-by: Martin Hundebøll Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/rx-offload.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/net/can/rx-offload.c +++ b/drivers/net/can/rx-offload.c @@ -216,8 +216,10 @@ int can_rx_offload_queue_sorted(struct c unsigned long flags; if (skb_queue_len(&offload->skb_queue) > - offload->skb_queue_len_max) - return -ENOMEM; + offload->skb_queue_len_max) { + kfree_skb(skb); + return -ENOBUFS; + } cb = can_rx_offload_get_cb(skb); cb->timestamp = timestamp;