From patchwork Sat Oct 22 07:22:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1095010wrr; Sat, 22 Oct 2022 01:01:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM74DZ6Mujyi6Ke0mA1xsO0QJou9mWVOhe/5bW3sq5c3o3x9osdGmI/PXKBvG5H69p9YKLcc X-Received: by 2002:a17:902:b089:b0:178:54cf:d692 with SMTP id p9-20020a170902b08900b0017854cfd692mr22933646plr.1.1666425690051; Sat, 22 Oct 2022 01:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425690; cv=none; d=google.com; s=arc-20160816; b=z7kozZKCasWD4uO/g0dTbLm0HU0sW/qfe92QCsr/gLLeobYXZXKmROg3USexvIim3C t7l/uUY9Vc8PYiIL7E3At4VXFASH2aDHgy9NrWXJ4LLROQ3T+Bivuc0DAS9AblFLP+4m LDaicbOsi8Dl7oNu5o6D0k7S+gXkDD4oQ4oiddfNijThKooGqK1/6S0f6vEIsUCyMyrz 8Hmcmak/QDV6A/QsygDeMga2NWlE+zv19Rpx3R054RtTTAJuDVfbeZRoqWMHILFxewQv 86wiz4Gl0JRBMqLG2HzZhHwYkvEea3rm9n5CaBo7Sx7QCFDgOhMiruN6k50ltwkx14QR 5Uwg== 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=wOaPGhvn4wPLOJ8GCCUbrJ1NIB1B85jILs31EDFG4lQ=; b=zL5HTnAb/4TN6qSk7hUn7+Hha0lCeBCRVGkPE2TSvsRhujcJd3GakUlLmaNcGXKToI rCTk8vyptH5kBNYP2AOD23sJNWZbiLUx1o57m7JnGeKyv6VryD1/sraihORPgT9wIPm4 1E3XVJP1HpsTSmV5BGj18CCyT3MmGGs23uz1mEzaKkHlo07DZGNBURS6GwGLKdevFlPo 1uen5aQV4b3Gho3OTOgyqRaJqVTeTT9tgl79d77ULxDr02rtfWaIKb0Brv07rKeBv6qG PPdn/ekQZ/AOBEdsNrcB85DnYSGRudcAlILmrqZ2cGPKRCwz7Fv1ynea86zYGraODTtP ozKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wQ2G5z1Q; 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 k138-20020a628490000000b00562dda10caesi26464885pfd.245.2022.10.22.01.01.16; Sat, 22 Oct 2022 01:01:30 -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=wQ2G5z1Q; 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 S232273AbiJVIAw (ORCPT + 99 others); Sat, 22 Oct 2022 04:00:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232184AbiJVHyV (ORCPT ); Sat, 22 Oct 2022 03:54:21 -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 8BF402CA7E3; Sat, 22 Oct 2022 00:47:20 -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 5298260B00; Sat, 22 Oct 2022 07:46:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A3BFC433D7; Sat, 22 Oct 2022 07:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424816; bh=jn6U7cWk9g7ErLccI+E2jIRBBJZlYMN6lO4atQmarNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wQ2G5z1QLAc2Fe29X6w6XD8ovLfP6U3rF8of2tJfWtC6JZQGZJf9X0oc7e9ieHGZw OmAwAGOmJ3pB/50SdQZRZTWfE3x2vbGTU8yUM9MaSu3JG7JBYalbWPOmPjzibRg/Xt U/76Pe1rtwk8yk5IML2ppBTnxIujCxE7DVIRSxNY= 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 5.19 287/717] net: prestera: acl: Add check for kmemdup Date: Sat, 22 Oct 2022 09:22:46 +0200 Message-Id: <20221022072504.324321512@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747373983926731060?= X-GMAIL-MSGID: =?utf-8?q?1747373983926731060?= 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 3a141f2db812..c0d4ddc18f87 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_acl.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_acl.c @@ -162,10 +162,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 f963e1e0c0f0..21dbfe4fe5b8 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 4d93ad6a284c..553413248823 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_flower.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_flower.c @@ -428,7 +428,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 @@ -444,6 +446,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: