From patchwork Thu Jun 3 16:38:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 453822 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 713B6C47097 for ; Thu, 3 Jun 2021 16:40:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B56C613EE for ; Thu, 3 Jun 2021 16:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbhFCQls (ORCPT ); Thu, 3 Jun 2021 12:41:48 -0400 Received: from mail-lj1-f174.google.com ([209.85.208.174]:42941 "EHLO mail-lj1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbhFCQlr (ORCPT ); Thu, 3 Jun 2021 12:41:47 -0400 Received: by mail-lj1-f174.google.com with SMTP id a4so7916130ljq.9; Thu, 03 Jun 2021 09:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GtCPxP0lPvrT9tJ+M3sA6gONSBsSe+vnuidKP6YRQa8=; b=Li0wZbaVcRzZd0WkoeT/7oYvQPgKHlbfqgRd6v68EbjXePmp8a9T0eBWubriESk7G9 HLqGT1cxhXWwb8FhnBWh/RjNek3gkgIoEywvEvGZFCMqBExa+kdau4eUNRWMQqAgyWdS U10JuXD9R3a71nGx1ZE5yHyFsCKtx0m4exfPSgDT9vqPtRCo9BPeBT+tSZ1rOSJcN0km iSC1J7LDi9fqr/FljHfci9hmC6S2PcUfJcBUXhURR4oqme2/Q/4suibG9d9cuBr4HGfy SMydqIi+rgwAFM0b6OSZ8QFXGWfUMsuJJcSv6seiTR/nPOfrWDGhfzaIQAbBCIbLwc3k B1vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GtCPxP0lPvrT9tJ+M3sA6gONSBsSe+vnuidKP6YRQa8=; b=NVDLJKYGUY3FCwKuzWm/US8mKA2sk8KAwGCZE0uWh5vk/Je13762LMw1EBbjG6i6lw qrPiuDHdAuIHco66eoHHLmTtjhdR7LwUG1XpJSR/tJYs5TjnkkUYc2Y6sThJYCYf6bRk MhR/uHm3Xgi2BKGFsNPW8maIGDuIyENXKphGBFN4t9Z3Dxx4Be+rD0ou9OD1oX9/JDW2 BGEuPywoDCDqY26Hrkg9J+JwOYnAMTFKRGyjHJ4RomJEAVGLMBi0XeYuodUk2GhvPOqX 4rTr7SqKW61TuV00+aNXmlg+HZwV9hPPeka6jsn6w2VReDa/nPbKSdnaEitCy13X4gcL uqQQ== X-Gm-Message-State: AOAM531HNDfhmcizYtAWJ8ki7qj5nhDVs1WrY3NmGh/ck7qoNz5pAzDQ 7qC4IFk0+Km6t1F53bAQcH8= X-Google-Smtp-Source: ABdhPJz3LMpgEbt0Qcqe6W/p6dKpJTGBtnZblxXx5uInT8cHdd0M7UyM4m6Oeb1+xEHpcP0t3t2Whg== X-Received: by 2002:a2e:6c1a:: with SMTP id h26mr210990ljc.34.1622738325305; Thu, 03 Jun 2021 09:38:45 -0700 (PDT) Received: from localhost.localdomain ([94.103.224.40]) by smtp.gmail.com with ESMTPSA id v24sm365798lfp.37.2021.06.03.09.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 09:38:44 -0700 (PDT) From: Pavel Skripkin To: davem@davemloft.net, kuba@kernel.org, sjur.brandeland@stericsson.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Skripkin , stable@vger.kernel.org Subject: [PATCH 1/4] net: caif: added cfserl_release function Date: Thu, 3 Jun 2021 19:38:12 +0300 Message-Id: <0a34ac711f54b97d7041f4fe580dc14fb33177fd.1622737854.git.paskripkin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Added cfserl_release() function. Cc: stable@vger.kernel.org Signed-off-by: Pavel Skripkin --- include/net/caif/cfserl.h | 1 + net/caif/cfserl.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/net/caif/cfserl.h b/include/net/caif/cfserl.h index 14a55e03bb3c..67cce8757175 100644 --- a/include/net/caif/cfserl.h +++ b/include/net/caif/cfserl.h @@ -9,4 +9,5 @@ #include struct cflayer *cfserl_create(int instance, bool use_stx); +void cfserl_release(struct cflayer *layer); #endif diff --git a/net/caif/cfserl.c b/net/caif/cfserl.c index e11725a4bb0e..40cd57ad0a0f 100644 --- a/net/caif/cfserl.c +++ b/net/caif/cfserl.c @@ -31,6 +31,11 @@ static int cfserl_transmit(struct cflayer *layr, struct cfpkt *pkt); static void cfserl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, int phyid); +void cfserl_release(struct cflayer *layer) +{ + kfree(layer); +} + struct cflayer *cfserl_create(int instance, bool use_stx) { struct cfserl *this = kzalloc(sizeof(struct cfserl), GFP_ATOMIC); From patchwork Thu Jun 3 16:38:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 454597 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 DA98EC47098 for ; Thu, 3 Jun 2021 16:40:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1131613FA for ; Thu, 3 Jun 2021 16:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbhFCQlx (ORCPT ); Thu, 3 Jun 2021 12:41:53 -0400 Received: from mail-lj1-f182.google.com ([209.85.208.182]:34336 "EHLO mail-lj1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbhFCQlw (ORCPT ); Thu, 3 Jun 2021 12:41:52 -0400 Received: by mail-lj1-f182.google.com with SMTP id bn21so7972629ljb.1; Thu, 03 Jun 2021 09:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H8lb6eizzgSPHFKT9be5e/0O9La7mP/YjKJCQ8I16io=; b=pG0JQoeA1S0PfLGQcQH0N3epPCHliz0S+PkeQP1MoU9TNBKm2X56q+NIN6f2s5FX5k QKKte6eebjEeq980f/7XLEVeCsrIymjBqudo1A2MXth+LSonq2Zchss1lMZpJhpJaoK/ TDS35CPinQffWqoLoLmq3tyFhA9aB5yn2HnmNZxWOFpoXhmy7u+QUK4duiFdjON3d+7U C9PrJS+4MRle9LacmZdfKdOyPOy4DmlVbZOKSGNKlJfCArksrXL9bxl8JoSMZaA7vSh2 qrdEewFjrBWXEWI0TqHE58qVp/h3tAmL5yNItfP99olcgjU3o9GxjEKC5LwIgeYXeiBa UpbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H8lb6eizzgSPHFKT9be5e/0O9La7mP/YjKJCQ8I16io=; b=qqqCrlQXheXBd72wIA1N7Zz7b+4liq/S7c2KV0j1mJXILCUAb7Dg4naLz9/3eYeLqQ V/Pd9Dsu7F6VPTy6g1Qg3i1EY6Yc6QYufav0uTXhlZaaav5SRtppJe0F6ggU9F6pUdLI yj7IeYyxovueBudRIDLxmYmNHNvkNIaicLhlDjodNgZ0fRpA0mztXNZaE95rTETnHjKP R0ZTct71R1zhUMeHomFn/6E1OO+s01xIfb90HCXhUufbSQBhMnmEEm1X9HyWw8LmWJgD yZdy8JlqTR+HVxExDQLkyBLjJc5uZVOUQv47SmPx+AahyZV9dQ4WU9qUvl2Q3FlIaGYX VxnQ== X-Gm-Message-State: AOAM530HJ8uDO9czBKPUdy8soGVDuyue77VEpQBePNkFmKlmjPr5UoTZ 6xtAUCkTla8T7YKGkrsJAlQ= X-Google-Smtp-Source: ABdhPJx5UPMFVe3Hb8Rpi3z/mkT74p4T57S3sTtcSOLeUrn5icPJCnprOwRHuV9vQ7Dc7Wru3YNdJw== X-Received: by 2002:a2e:994c:: with SMTP id r12mr183686ljj.235.1622738335897; Thu, 03 Jun 2021 09:38:55 -0700 (PDT) Received: from localhost.localdomain ([94.103.224.40]) by smtp.gmail.com with ESMTPSA id e29sm360067lfb.258.2021.06.03.09.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 09:38:55 -0700 (PDT) From: Pavel Skripkin To: davem@davemloft.net, kuba@kernel.org, sjur.brandeland@stericsson.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Skripkin , stable@vger.kernel.org Subject: [PATCH 2/4] net: caif: add proper error handling Date: Thu, 3 Jun 2021 19:38:51 +0300 Message-Id: <13757f9aaea3484864b8149365b4361eb802853b.1622737854.git.paskripkin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org caif_enroll_dev() can fail in some cases. Ingnoring these cases can lead to memory leak due to not assigning link_support pointer to anywhere. Fixes: 7c18d2205ea7 ("caif: Restructure how link caif link layer enroll") Cc: stable@vger.kernel.org Signed-off-by: Pavel Skripkin --- include/net/caif/caif_dev.h | 2 +- include/net/caif/cfcnfg.h | 2 +- net/caif/caif_dev.c | 8 +++++--- net/caif/cfcnfg.c | 16 +++++++++++----- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/net/caif/caif_dev.h b/include/net/caif/caif_dev.h index 48ecca8530ff..b655d8666f55 100644 --- a/include/net/caif/caif_dev.h +++ b/include/net/caif/caif_dev.h @@ -119,7 +119,7 @@ void caif_free_client(struct cflayer *adap_layer); * The link_support layer is used to add any Link Layer specific * framing. */ -void caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev, +int caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev, struct cflayer *link_support, int head_room, struct cflayer **layer, int (**rcv_func)( struct sk_buff *, struct net_device *, diff --git a/include/net/caif/cfcnfg.h b/include/net/caif/cfcnfg.h index 2aa5e91d8457..8819ff4db35a 100644 --- a/include/net/caif/cfcnfg.h +++ b/include/net/caif/cfcnfg.h @@ -62,7 +62,7 @@ void cfcnfg_remove(struct cfcnfg *cfg); * @fcs: Specify if checksum is used in CAIF Framing Layer. * @head_room: Head space needed by link specific protocol. */ -void +int cfcnfg_add_phy_layer(struct cfcnfg *cnfg, struct net_device *dev, struct cflayer *phy_layer, enum cfcnfg_phy_preference pref, diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c index c10e5a55758d..fffbe41440b3 100644 --- a/net/caif/caif_dev.c +++ b/net/caif/caif_dev.c @@ -308,7 +308,7 @@ static void dev_flowctrl(struct net_device *dev, int on) caifd_put(caifd); } -void caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev, +int caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev, struct cflayer *link_support, int head_room, struct cflayer **layer, int (**rcv_func)(struct sk_buff *, struct net_device *, @@ -319,11 +319,12 @@ void caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev, enum cfcnfg_phy_preference pref; struct cfcnfg *cfg = get_cfcnfg(dev_net(dev)); struct caif_device_entry_list *caifdevs; + int res; caifdevs = caif_device_list(dev_net(dev)); caifd = caif_device_alloc(dev); if (!caifd) - return; + return -ENOMEM; *layer = &caifd->layer; spin_lock_init(&caifd->flow_lock); @@ -344,7 +345,7 @@ void caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev, strlcpy(caifd->layer.name, dev->name, sizeof(caifd->layer.name)); caifd->layer.transmit = transmit; - cfcnfg_add_phy_layer(cfg, + res = cfcnfg_add_phy_layer(cfg, dev, &caifd->layer, pref, @@ -354,6 +355,7 @@ void caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev, mutex_unlock(&caifdevs->lock); if (rcv_func) *rcv_func = receive; + return res; } EXPORT_SYMBOL(caif_enroll_dev); diff --git a/net/caif/cfcnfg.c b/net/caif/cfcnfg.c index 399239a14420..cac30e676ac9 100644 --- a/net/caif/cfcnfg.c +++ b/net/caif/cfcnfg.c @@ -450,7 +450,7 @@ cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, enum cfctrl_srv serv, rcu_read_unlock(); } -void +int cfcnfg_add_phy_layer(struct cfcnfg *cnfg, struct net_device *dev, struct cflayer *phy_layer, enum cfcnfg_phy_preference pref, @@ -459,7 +459,7 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, { struct cflayer *frml; struct cfcnfg_phyinfo *phyinfo = NULL; - int i; + int i, res = 0; u8 phyid; mutex_lock(&cnfg->lock); @@ -473,12 +473,15 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, goto got_phyid; } pr_warn("Too many CAIF Link Layers (max 6)\n"); + res = -EEXIST; goto out; got_phyid: phyinfo = kzalloc(sizeof(struct cfcnfg_phyinfo), GFP_ATOMIC); - if (!phyinfo) + if (!phyinfo) { + res = -ENOMEM; goto out_err; + } phy_layer->id = phyid; phyinfo->pref = pref; @@ -492,8 +495,10 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, frml = cffrml_create(phyid, fcs); - if (!frml) + if (!frml) { + res = -ENOMEM; goto out_err; + } phyinfo->frm_layer = frml; layer_set_up(frml, cnfg->mux); @@ -511,11 +516,12 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, list_add_rcu(&phyinfo->node, &cnfg->phys); out: mutex_unlock(&cnfg->lock); - return; + return res; out_err: kfree(phyinfo); mutex_unlock(&cnfg->lock); + return res; } EXPORT_SYMBOL(cfcnfg_add_phy_layer); From patchwork Thu Jun 3 16:39:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 454598 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 9B111C47096 for ; Thu, 3 Jun 2021 16:39:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FD13613F3 for ; Thu, 3 Jun 2021 16:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230025AbhFCQlO (ORCPT ); Thu, 3 Jun 2021 12:41:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbhFCQlO (ORCPT ); Thu, 3 Jun 2021 12:41:14 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23DDDC06174A; Thu, 3 Jun 2021 09:39:17 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id v8so9785743lft.8; Thu, 03 Jun 2021 09:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VmLmkvFwr4n9oRDeOXVoYKwRtcm1cme7qf3DqyZC2S4=; b=SgwD40QBfynEskonig0PPw/VLdgzg3TOt6NT8a6yf7klKA7NIIKiM9cCJzqCo73W6B PpB9n52Xcgg+/dByRQBH+jpcDuD5vqig//N0FQ6edFH/OCdR8qjZ71l2l29M0tRWBSV8 c+QrYXg1mRkrpV/K103H0Gm6OkmqGTpf/SMGbj1Sqv49xACJMEBkhc02FlD7q40zLCwY 1mMkmfkjTOw4mDJ8u+nupf4F1YefceIqM73sO/hv52enR2M9IMc5SgXh4LPyj+8OOwjb rYWCwQG374vnm69Sox+DjCrUBfuq5h9rd5WaMad62gxrdHHv3bX7PXhCr8AFYSzc4hjL o1pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VmLmkvFwr4n9oRDeOXVoYKwRtcm1cme7qf3DqyZC2S4=; b=R9HpVt8DTE7CgpZ0Icl0uv0RoUdmFsFWQrLwM6p4Kj2oY83AZ58elVuu7Vo5YDQJtH DqoermNgfQ6ptPLF5FR3Qh6OMRGDtqDRsNSzlEK2L2uRvb5w/sEiYj5KytS+2SlXSpPF Puq/7mLDCIsUG0OrE9xzVvH8Dw0/ety4hkfsRhZY5CkmyALGiKrouJSOqyEGwz/ANkGZ 9MX147nRbfKvHi5gHtj7faIgApEYWPYHeybKha3KLJU9wda8KDwcMGs+nQPVe0r9x1rU oW6AM3gtcW8L98rgtcYCeVgB5b16CYiIHSrNL8knts+OEzimCE6Jgl5mBznU830xTuI0 ndaw== X-Gm-Message-State: AOAM5301eqHSU20v/+yuz8pCFXvpBjNYrg2z5qXcJ/oFyBD0wUCBv1xj FC+heHapjMPWQpkMQNlkVoQ= X-Google-Smtp-Source: ABdhPJz2jSYS5l86vc8NwNRO5iBauzOK+6UV1BuHhTsM3GwzuSxNWoxoPFjAY+SeP30QguIttMV4Ng== X-Received: by 2002:a05:6512:21ae:: with SMTP id c14mr334669lft.483.1622738355485; Thu, 03 Jun 2021 09:39:15 -0700 (PDT) Received: from localhost.localdomain ([94.103.224.40]) by smtp.gmail.com with ESMTPSA id m3sm363468lfk.76.2021.06.03.09.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 09:39:14 -0700 (PDT) From: Pavel Skripkin To: davem@davemloft.net, kuba@kernel.org, sjur.brandeland@stericsson.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Skripkin , stable@vger.kernel.org, syzbot+7ec324747ce876a29db6@syzkaller.appspotmail.com Subject: [PATCH 3/4] net: caif: fix memory leak in caif_device_notify Date: Thu, 3 Jun 2021 19:39:11 +0300 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In case of caif_enroll_dev() fail, allocated link_support won't be assigned to the corresponding structure. So simply free allocated pointer in case of error Fixes: 7c18d2205ea7 ("caif: Restructure how link caif link layer enroll") Cc: stable@vger.kernel.org Reported-and-tested-by: syzbot+7ec324747ce876a29db6@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin --- net/caif/caif_dev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c index fffbe41440b3..440139706130 100644 --- a/net/caif/caif_dev.c +++ b/net/caif/caif_dev.c @@ -370,6 +370,7 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what, struct cflayer *layer, *link_support; int head_room = 0; struct caif_device_entry_list *caifdevs; + int res; cfg = get_cfcnfg(dev_net(dev)); caifdevs = caif_device_list(dev_net(dev)); @@ -395,8 +396,10 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what, break; } } - caif_enroll_dev(dev, caifdev, link_support, head_room, + res = caif_enroll_dev(dev, caifdev, link_support, head_room, &layer, NULL); + if (res) + cfserl_release(link_support); caifdev->flowctrl = dev_flowctrl; break; From patchwork Thu Jun 3 16:39:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 453821 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, 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 5C3CEC47098 for ; Thu, 3 Jun 2021 16:40:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47A8B613EE for ; Thu, 3 Jun 2021 16:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230231AbhFCQmZ (ORCPT ); Thu, 3 Jun 2021 12:42:25 -0400 Received: from mail-lf1-f42.google.com ([209.85.167.42]:36647 "EHLO mail-lf1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbhFCQmY (ORCPT ); Thu, 3 Jun 2021 12:42:24 -0400 Received: by mail-lf1-f42.google.com with SMTP id v22so8449470lfa.3; Thu, 03 Jun 2021 09:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lV6Q3W6nkSdzK3hzB+sseFLCHuZyidZULCgpSSGeWe4=; b=sT3XU+v2p8XVmtVvsVXgp+Mmwyh4QJOmaJUdQms1f8UCaglDdkxU/mKixEj+WrTzIG mRxNzwcZyc+MEVwmK5wZlffXeDGYIov/Z+36+TaAijhjW8mrhed13JMt02aiHAfx4/vz 2PR+ckX7M8vcaquHysmQEYQc8E/+vO6uxtXxF6cNkfRYzbKzQGwHk1k/7pPKlAsiYRoW u3f2jo6MD6D6dUGRbg90BkMRzzJ5DV/fNL96XHmS10AJj0W7HmSTUYZk6NQKx33eoKT8 6jYuITumEvCV3Uwn6aw1ldwA4CY55z+v9CaYTr2tLY97Ywrfid3Ny9pXLw8fej3JzGFu 2hPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lV6Q3W6nkSdzK3hzB+sseFLCHuZyidZULCgpSSGeWe4=; b=QQF7S5sOXzFOjVjH0FhfFahfxj+AnNIOl1HfpnkpPxQLYNtg0I0Oo6hNJmyxFG3FEZ WRSCs+i1X85WAzp5xXzD6aG/6godBty1ABPNh/8DmWnGQh8l3qoF9eD35Vb/xUnlEKBB G08HseZdvVSBj89ejpW3YfAzptrjTZW1HSNfvtnnv2cXvRPv9GpphxXxyHd0gbwQjl44 MriMgsOkz5SsREnXPFTeHgqm9PS3aUIOPDI/9HEquXH253CfZkB/GVFyNU41uVSv1347 0plaPSVaag8ofANZhxYG3rstJ32LZJ0HwT77MczWOGBIUkCQ9KkBdKuPT1Y7bVYqeVvX ex7A== X-Gm-Message-State: AOAM5316vbZjBJyc52MNfPhxL3ZCH6MHzZ6rYWY4Ly0ngq1ufKmoFQso wO61D1U6i+Oi711Wi8CPGME= X-Google-Smtp-Source: ABdhPJwTH5GT/8hnHzguYo9DcNtmZG54O90JBEoIzXGtAGwQfHJqXULHxgHKKYZkOGwLQLZzhyaK5Q== X-Received: by 2002:a19:c34a:: with SMTP id t71mr321369lff.499.1622738378208; Thu, 03 Jun 2021 09:39:38 -0700 (PDT) Received: from localhost.localdomain ([94.103.224.40]) by smtp.gmail.com with ESMTPSA id f5sm363332lfh.178.2021.06.03.09.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 09:39:37 -0700 (PDT) From: Pavel Skripkin To: davem@davemloft.net, kuba@kernel.org, sjur.brandeland@stericsson.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Skripkin , stable@vger.kernel.org Subject: [PATCH 4/4] net: caif: fix memory leak in cfusbl_device_notify Date: Thu, 3 Jun 2021 19:39:35 +0300 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In case of caif_enroll_dev() fail, allocated link_support won't be assigned to the corresponding structure. So simply free allocated pointer in case of error. Fixes: 7ad65bf68d70 ("caif: Add support for CAIF over CDC NCM USB interface") Cc: stable@vger.kernel.org Signed-off-by: Pavel Skripkin --- net/caif/caif_usb.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/net/caif/caif_usb.c b/net/caif/caif_usb.c index a0116b9503d9..b02e1292f7f1 100644 --- a/net/caif/caif_usb.c +++ b/net/caif/caif_usb.c @@ -115,6 +115,11 @@ static struct cflayer *cfusbl_create(int phyid, u8 ethaddr[ETH_ALEN], return (struct cflayer *) this; } +static void cfusbl_release(struct cflayer *layer) +{ + kfree(layer); +} + static struct packet_type caif_usb_type __read_mostly = { .type = cpu_to_be16(ETH_P_802_EX1), }; @@ -127,6 +132,7 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what, struct cflayer *layer, *link_support; struct usbnet *usbnet; struct usb_device *usbdev; + int res; /* Check whether we have a NCM device, and find its VID/PID. */ if (!(dev->dev.parent && dev->dev.parent->driver && @@ -169,8 +175,11 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what, if (dev->num_tx_queues > 1) pr_warn("USB device uses more than one tx queue\n"); - caif_enroll_dev(dev, &common, link_support, CFUSB_MAX_HEADLEN, + res = caif_enroll_dev(dev, &common, link_support, CFUSB_MAX_HEADLEN, &layer, &caif_usb_type.func); + if (res) + goto err; + if (!pack_added) dev_add_pack(&caif_usb_type); pack_added = true; @@ -178,6 +187,9 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what, strlcpy(layer->name, dev->name, sizeof(layer->name)); return 0; +err: + cfusbl_release(link_support); + return res; } static struct notifier_block caif_device_notifier = {