From patchwork Thu Sep 16 01:43:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 513523 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham 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 51814C433EF for ; Thu, 16 Sep 2021 01:43:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28D3861164 for ; Thu, 16 Sep 2021 01:43:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233709AbhIPBpO (ORCPT ); Wed, 15 Sep 2021 21:45:14 -0400 Received: from smtp23.cstnet.cn ([159.226.251.23]:39544 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229600AbhIPBpM (ORCPT ); Wed, 15 Sep 2021 21:45:12 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-03 (Coremail) with SMTP id rQCowADHzno9oUJh3yyVAA--.47849S2; Thu, 16 Sep 2021 09:43:25 +0800 (CST) From: Jiasheng Jiang To: pshelar@ovn.org, davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, dev@openvswitch.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] openvswitch: Fix condition check by using nla_ok() Date: Thu, 16 Sep 2021 01:43:23 +0000 Message-Id: <1631756603-3706451-1-git-send-email-jiasheng@iscas.ac.cn> X-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IFyTuYvjfUOMKZDUUUU X-Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Just using 'rem > 0' might be unsafe, so it's better to use the nla_ok() instead. Because we can see from the nla_next() that '*remaining' might be smaller than 'totlen'. And nla_ok() will avoid it happening. Signed-off-by: Jiasheng Jiang --- net/openvswitch/actions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 77d924a..116e38a 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -1238,7 +1238,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, const struct nlattr *a; int rem; - for (a = attr, rem = len; rem > 0; + for (a = attr, rem = len; nla_ok(a, rem); a = nla_next(a, &rem)) { int err = 0;