Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp983241pxb; Wed, 15 Sep 2021 18:51:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE0OGyoXvsrOSqRXe1uCUVvYXL6z407yprok3xI0sWbr7wqL3cZmf52Nl2Em0IB6Ule9xC X-Received: by 2002:a05:6402:270a:: with SMTP id y10mr3430643edd.252.1631757061178; Wed, 15 Sep 2021 18:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631757061; cv=none; d=google.com; s=arc-20160816; b=oevzVndmb5DdsE4ON3kM/+I9NX7bIilu199KRWfl+iVog6IKltyJVL5tqfP3jIyKXX DcM/yepnEM3Ydkn6uF/KGqYeVOwnIfzlt1jUHJsc/pERlWNM7hLSaSI0hhbFnbynD013 tPjtBHueejJBbibT9GxKe9zj+Xp/DlWmC9DkQoW4fZPiOnBJrrPkkdpAHzmY5PJWQJDX NNepaUuN9N+aNfsGJ3M+38W9/vb5xv+6S4EWZFOSMKhnfmBV3U8HF3aV5P9Wbz5+SaTM gFNt/ef6WxE8SVa/Ttgg0lKQFC9DmJcLk2Av7oPNU8PKo7rGatu8vafEHP1s5CnLhZla Af5Q== 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=w+yxpbhEZhVclF5BXyFSUIjm8brKWL5wSLYCUUtog5Q=; b=FlX7lwHwZF5JlBolv8uEcTOv/XULYZFdZceo1b/51Bq/1vQDCEfzrqR0CmfjFmtA8K cmqdtZmhysdXyGuEpnDhnW83qGbMPRBjncSYjr6+tLINLz8C0122cKTspphQZ+ZPRweQ uwCPRLjlt47baQ20lYafKl4L+G96oUKyvBFhWv8XoW/joBdduqbdhBhS7pAS84HX2YjM mzz9wRmwCjGy2S6vMfAG3NZoKMfy36y+OIIVUuFipPcauTMhRdYn2Fz8Tfh8+vzrMGM1 7TeO8K6tngC22Q+HTv47HQp07/Ra51TaKK3Yc+ALt8ERAE6W3Umsf3CSoxzog34EXUOZ WCJQ== 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 u33si1941485edc.86.2021.09.15.18.50.38; Wed, 15 Sep 2021 18:51: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 S233831AbhIPBuX (ORCPT + 99 others); Wed, 15 Sep 2021 21:50:23 -0400 Received: from smtp23.cstnet.cn ([159.226.251.23]:47524 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233809AbhIPBuV (ORCPT ); Wed, 15 Sep 2021 21:50:21 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-03 (Coremail) with SMTP id rQCowADn7Xl1okJhgDmVAA--.28835S2; Thu, 16 Sep 2021 09:48:38 +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:48:36 +0000 Message-Id: <1631756916-3759083-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: rQCowADn7Xl1okJhgDmVAA--.28835S2 X-Coremail-Antispam: 1UD129KBjvdXoWrtr13GrW5uF1xAry8XF15twb_yoWfZrcEka n3t3ykW3y2yw4SkF48Jws0yrn2vr1fWrnY9w13KFZxA340qwsxuwn8GFZ7Jr18ur17Zr9x Wan3tr1YgF47ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb4xFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_ Gr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr 1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_ KwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr 0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j6r4U MIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUChFxUUU UU= 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. 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 116e38a..8209ab1 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -915,7 +915,7 @@ static int output_userspace(struct datapath *dp, struct sk_buff *skb, upcall.cmd = OVS_PACKET_CMD_ACTION; upcall.mru = OVS_CB(skb)->mru; - for (a = nla_data(attr), rem = nla_len(attr); rem > 0; + for (a = nla_data(attr), rem = nla_len(attr); nla_ok(a, rem); a = nla_next(a, &rem)) { switch (nla_type(a)) { case OVS_USERSPACE_ATTR_USERDATA: -- 2.7.4