From patchwork Wed Oct 19 08:27:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp226206wrs; Wed, 19 Oct 2022 02:45:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6bKDEKTub+QvoXKTqU328oU+awpbeawtjgV15LbUQUJ45QJk6/1PpP0peh0+/O//6sOQw2 X-Received: by 2002:a17:907:1c17:b0:78d:df89:26c6 with SMTP id nc23-20020a1709071c1700b0078ddf8926c6mr6270989ejc.20.1666172600933; Wed, 19 Oct 2022 02:43:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172600; cv=none; d=google.com; s=arc-20160816; b=mBEg5XHSLNKNl8rTQwkETP1oOiCnq1ijN7A8sVNXZnxKX3pWCqM52v1m0WQxJfvdKA uhFKaORunHihrCYtWZzw9xNpp86JvQkRhVavCTRayqd4tDw11b6UM6OXyTWzzDyVsrly gTeGpldjIImZHvftjGsrw/lb5gXI7cJlB40R67xtN2SAqJMMQKG31AHC7fSepfJnBSpw NkG8ahvqFtWazzWoZyadONW3p3e2vmvfbcTdwS2Gdc1QAs2GQwmh/Ta9pdo5pg2OlMBF eabnkbihYrBt3ZiYh7r17OaHNBZ8iRB4M/F02ZzZjbG0mRcIksn7mL+fkdtFJ/o7x7H3 R1Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oP8eedEWj6ZD0sD7ZMbIbuoN/P3SPUwH6tBzKZboaJQ=; b=TIEWoyJu8MEaPhMAy7MpA/zmrLF+0+f+LooumzmaixEVAOTkD/SJ2hdfZBQqDhirbK RRD618Gy34LER0By9t2jEAMUVjH4BfKjDXPdSbs86MV1CXRC1cTE/gzrL62A68UBVc9J aCIafdoeLnXd/9mW3qhdZmeq/k7+uV00jTcnjYA+iJb1upESEnq1+U34RrVgeG8gDpn0 VLMhHPBtOjNX8JIzA74Hg9+y3B5qw5zx/AlOZwgF7JX/Hk+r1+9V+4Y6s1vKnqJ3rWek +13bu9jLr2wjSIrE7Xm/LQYxAf2hq2bmoaemJEAgZTPObHgZhji+BzGoWhmvu016xZgX i+mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GS5yOWPN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g12-20020aa7c84c000000b00459c2ac54e2si12570696edt.255.2022.10.19.02.42.55; Wed, 19 Oct 2022 02:43:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GS5yOWPN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233994AbiJSJeT (ORCPT + 99 others); Wed, 19 Oct 2022 05:34:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233789AbiJSJ31 (ORCPT ); Wed, 19 Oct 2022 05:29:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86138EAC85; Wed, 19 Oct 2022 02:12:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EE86A61826; Wed, 19 Oct 2022 08:55:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F059C433D6; Wed, 19 Oct 2022 08:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169716; bh=94Vil/zmhvmsJ0iy/6ZnYelSEc/3VoLdzE2dwZt/+lw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GS5yOWPNqSSMGvu8AwFZ3YCb8tv7gda4bthxA/1wKG5kZJ7pqjQQE6NsH+a01HRzm 6TDhRn/uqtrx51Sn8d88NEXvgM7/PkirNIka8NZFS/GgfNsW8Pfig+n4cIPY18dHMT oqg3Lh6uaofJHidasvUnOqk8BTnJNsviLezFw8S4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , Taras Chornyi , "David S. Miller" , Sasha Levin Subject: [PATCH 6.0 338/862] net: prestera: acl: Add check for kmemdup Date: Wed, 19 Oct 2022 10:27:05 +0200 Message-Id: <20221019083304.999767544@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747108601398996245?= X-GMAIL-MSGID: =?utf-8?q?1747108601398996245?= From: Jiasheng Jiang [ Upstream commit 9e6fd874c7bb47b6a4295abc4c81b2f41b97e970 ] As the kemdup could return NULL, it should be better to check the return value and return error if fails. Moreover, the return value of prestera_acl_ruleset_keymask_set() should be checked by cascade. Fixes: 604ba230902d ("net: prestera: flower template support") Signed-off-by: Jiasheng Jiang Reviewed-by: Taras Chornyi Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/marvell/prestera/prestera_acl.c | 8 ++++++-- drivers/net/ethernet/marvell/prestera/prestera_acl.h | 4 ++-- drivers/net/ethernet/marvell/prestera/prestera_flower.c | 6 +++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_acl.c b/drivers/net/ethernet/marvell/prestera/prestera_acl.c index 3d4b85f2d541..f6b2933859d0 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_acl.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_acl.c @@ -178,10 +178,14 @@ prestera_acl_ruleset_create(struct prestera_acl *acl, return ERR_PTR(err); } -void prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset, - void *keymask) +int prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset, + void *keymask) { ruleset->keymask = kmemdup(keymask, ACL_KEYMASK_SIZE, GFP_KERNEL); + if (!ruleset->keymask) + return -ENOMEM; + + return 0; } int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_acl.h b/drivers/net/ethernet/marvell/prestera/prestera_acl.h index 03fc5b9dc925..131bfbc87cd7 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_acl.h +++ b/drivers/net/ethernet/marvell/prestera/prestera_acl.h @@ -185,8 +185,8 @@ struct prestera_acl_ruleset * prestera_acl_ruleset_lookup(struct prestera_acl *acl, struct prestera_flow_block *block, u32 chain_index); -void prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset, - void *keymask); +int prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset, + void *keymask); bool prestera_acl_ruleset_is_offload(struct prestera_acl_ruleset *ruleset); int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset); void prestera_acl_ruleset_put(struct prestera_acl_ruleset *ruleset); diff --git a/drivers/net/ethernet/marvell/prestera/prestera_flower.c b/drivers/net/ethernet/marvell/prestera/prestera_flower.c index 19d3b55c578e..cf551a8379ac 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_flower.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_flower.c @@ -452,7 +452,9 @@ int prestera_flower_tmplt_create(struct prestera_flow_block *block, } /* preserve keymask/template to this ruleset */ - prestera_acl_ruleset_keymask_set(ruleset, rule.re_key.match.mask); + err = prestera_acl_ruleset_keymask_set(ruleset, rule.re_key.match.mask); + if (err) + goto err_ruleset_keymask_set; /* skip error, as it is not possible to reject template operation, * so, keep the reference to the ruleset for rules to be added @@ -468,6 +470,8 @@ int prestera_flower_tmplt_create(struct prestera_flow_block *block, list_add_rcu(&template->list, &block->template_list); return 0; +err_ruleset_keymask_set: + prestera_acl_ruleset_put(ruleset); err_ruleset_get: kfree(template); err_malloc: