Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2268133pxb; Fri, 17 Sep 2021 06:12:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwDAYy40Ib/fkX/3bK3m8LfVMpmwvq+iEFS28R64HNONCmbQCFkiv0S0cbJwS7rNF4YAfR X-Received: by 2002:a1c:800e:: with SMTP id b14mr15535075wmd.54.1631884321570; Fri, 17 Sep 2021 06:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631884321; cv=none; d=google.com; s=arc-20160816; b=YCtbkGBumynm8kvhHVBzS80jGOR0BlFolLHa5P5HKau41FI2sjzswj2q1qK7LtFRtO WWFe3rXE13l0vqqKCLKEJt+j7Okq+xOmQhS8RJTHHQK3cjZKc8tBAelPc2oP88R5GSkl eKJrpStNFtyuadgC1jbmmAw0BXPIWXpjumLdjwPlGmxHqJwV5+K2B0acUP954l0SzR+C f34wIB0dVwTBk01seXZNG+9BrMvFlzVFxwVVY5zes75xKACe+TpyMpMG8dsijtcj4lvy KfX3exEiVgzj0xEn7WX3zqKK4o0tZ0c4/dTfGTDdv6NEe9beJ/3mnTQpJGMx2fAOuJIU Phug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=EoNcCqPixe/Bp10mCLHq0p23J235CCEJWIsGs7igq5g=; b=bwxWPrDfJBVMUdaH4aAyH9i0jsMgBgEiNxgL4oZ0Hd1brFyRasAri5vttUN6iC2lXa 6DTUmL5JWbJX/N884wKCiIwNYkx4tWBV0QeIlje0dqsPngI4Jtl2DpmwWPT0AjxRFEXc bxx//F97xNBe85Q/j5bWVt8+/Vm5W9dcIxFvhfiMj9M3x2f4mv5X1fcsYME+GxO1QHVh bUeJPYixz8wGYZGNuXjSTWG8cK6Ynll7ze5HfOF0rOJVVneISGFv7Uez9wj30OdmezZc 8T9FlkDGRhxR4L2sBOy5qMgr4BNy+n/eFxHWUmcf1KOmRVuz6AncDy4gYV3iqbKinBOn f0Ww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k9si8062422edv.565.2021.09.17.06.11.33; Fri, 17 Sep 2021 06:12:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245355AbhIQIJx (ORCPT + 99 others); Fri, 17 Sep 2021 04:09:53 -0400 Received: from smtp25.cstnet.cn ([159.226.251.25]:49028 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S245122AbhIQIJZ (ORCPT ); Fri, 17 Sep 2021 04:09:25 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-05 (Coremail) with SMTP id zQCowADn7KyzTERhVJzRAA--.3914S2; Fri, 17 Sep 2021 16:07:16 +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 v2] openvswitch: Fix condition check in do_execute_actions() by using nla_ok() Date: Fri, 17 Sep 2021 08:07:14 +0000 Message-Id: <1631866034-3869133-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: zQCowADn7KyzTERhVJzRAA--.3914S2 X-Coremail-Antispam: 1UD129KBjvdXoWrtr13GrW5uF1xWw48WFW5trb_yoWkXFcEkw s3KF1kXw42yrn5Kr48KwsYqw1vvr13Gr1F9wn8KFWay3sYqws8uws8GrZ3Jr18ur429F98 Xw43Ar4Yga13ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbc8FF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVAFwVW8ZwCF 04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r 18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vI r41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr 1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUeHUDDUUUU X-Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. For example, ovs_dp_process_packet() -> ovs_execute_actions() -> do_execute_actions(), and attr comes from OVS_CB(skb)->input_vport, which restores the received packet from the user space. Fixes: ccb1352e76cff0524e7ccb2074826a092dd13016 ('net: Add Open vSwitch kernel components.') Signed-off-by: Jiasheng Jiang --- net/openvswitch/actions.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 77d924a..c23537f 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -1238,8 +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; - a = nla_next(a, &rem)) { + nla_for_each_attr(a, attr, len, rem) { int err = 0; switch (nla_type(a)) { -- 2.7.4