Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2894382iog; Mon, 27 Jun 2022 05:15:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t6Rui/y2jU10QbIGs8tPMszGJXcb1ruZI5AkrxziR2d30AfJJ+punkgRyfDA8ykleOYk+T X-Received: by 2002:a17:907:2081:b0:726:b8d2:fba2 with SMTP id pv1-20020a170907208100b00726b8d2fba2mr1730317ejb.686.1656332124451; Mon, 27 Jun 2022 05:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656332124; cv=none; d=google.com; s=arc-20160816; b=LFIXMriTPV7QaTXS0+EXDCu/48dMZ9/j2Qv/u8Elhy3jpafvf76DhNgeGP6E+az+El PLrMNWyqyywmrgOXIeYKBXuwI+WiK6RsGqqe+EzUMmIRH9midgyTZkAgr8n4B18T9jWJ 87pBKxoNUkRP3FNsfi7+Y9ujIfciEIzXbJhB6Rkp0lm3o9JgrlGBN9D1t+42GqzOJg9P 7/D8DvHc1iRt198X9RedwaMci+kugGC+AekMi5y+z4tYbrEaxJIuK3rZ+1c94B1q32ee FupndaYjwDd4iSoF/hC27ES9u9+oaq8KnP0Y2kQDlxaDZqN4pylyD4KniaEp8KyVtEyY Fkzw== 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=KJcCxKBUePXfBIb2dLrRIMVO8N4G39aI0pNs/I6e4oc=; b=IBM/9CRZYeKb1nGbh5XZkNvFYvWqigWQUdZmAnY/oQDD804cNrRvQT/m4ae/U3rqFm erHLLLZ2v4xUd/dAYzouzivaOebGMAxfdQko/i7A/NjwstXgcEKS/5v8qpl/vpEHvQO6 yqW7eoyIMbXyD0P1WchAIPoWhSHdGFjxvVh8ZeMmLJ5dXcmSj1UgfFaNZpRS2+Ox7LjR yZK3S/F3bIWRRZPr+j/0B/Qq7OGyiXVWg4FKGOVH5JSYM4zMoZ18YGphc7Gjm80c9gz3 K9YLEm/BRbo1PuBR8223e5vXiuBWMNB7stbbRwouVZ05hPQ9OVivbgjIA+oPlTPPhIsG TTVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YGgZ8sR5; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc10-20020a1709078a0a00b00726b827dc70si1547797ejc.340.2022.06.27.05.14.59; Mon, 27 Jun 2022 05:15:24 -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=YGgZ8sR5; 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 S234745AbiF0LYk (ORCPT + 99 others); Mon, 27 Jun 2022 07:24:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234703AbiF0LYW (ORCPT ); Mon, 27 Jun 2022 07:24:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DAC56573; Mon, 27 Jun 2022 04:24:21 -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 ams.source.kernel.org (Postfix) with ESMTPS id E9D82B81122; Mon, 27 Jun 2022 11:24:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3090FC3411D; Mon, 27 Jun 2022 11:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656329058; bh=jCMUa1qxy25zcTSppi5OnwFRN6ISO/vpezVuczdRk88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YGgZ8sR54dPQCH/aVm4HTgdY2D+ZrxM2ayakwGReEckQP50svK0sOplbiGhX+xcSp 2TcV9wtZ56lQYppRNXXSsp49Qnwc99ektyqIa35Aciwi80cYGtJLOCF8eWr0b/n4TX hBwFcXcjYaXSfcB0Dl7llJScoElkD1lnniJEdEjU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yuming Chen , Cong Wang , Peilin Ye , Stephen Hemminger , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 035/102] net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms Date: Mon, 27 Jun 2022 13:20:46 +0200 Message-Id: <20220627111934.506359210@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111933.455024953@linuxfoundation.org> References: <20220627111933.455024953@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 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,T_SCC_BODY_TEXT_LINE 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 From: Peilin Ye [ Upstream commit a2b1a5d40bd12b44322c2ccd40bb0ec1699708b6 ] As reported by Yuming, currently tc always show a latency of UINT_MAX for netem Qdisc's on 32-bit platforms: $ tc qdisc add dev dummy0 root netem latency 100ms $ tc qdisc show dev dummy0 qdisc netem 8001: root refcnt 2 limit 1000 delay 275s 275s ^^^^^^^^^^^^^^^^ Let us take a closer look at netem_dump(): qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency, UINT_MAX); qopt.latency is __u32, psched_tdiff_t is signed long, (psched_tdiff_t)(UINT_MAX) is negative for 32-bit platforms, so qopt.latency is always UINT_MAX. Fix it by using psched_time_t (u64) instead. Note: confusingly, users have two ways to specify 'latency': 1. normally, via '__u32 latency' in struct tc_netem_qopt; 2. via the TCA_NETEM_LATENCY64 attribute, which is s64. For the second case, theoretically 'latency' could be negative. This patch ignores that corner case, since it is broken (i.e. assigning a negative s64 to __u32) anyways, and should be handled separately. Thanks Ted Lin for the analysis [1] . [1] https://github.com/raspberrypi/linux/issues/3512 Reported-by: Yuming Chen Fixes: 112f9cb65643 ("netem: convert to qdisc_watchdog_schedule_ns") Reviewed-by: Cong Wang Signed-off-by: Peilin Ye Acked-by: Stephen Hemminger Link: https://lore.kernel.org/r/20220616234336.2443-1-yepeilin.cs@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/sched/sch_netem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index 0c345e43a09a..adc5407fd5d5 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -1146,9 +1146,9 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) struct tc_netem_rate rate; struct tc_netem_slot slot; - qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency), + qopt.latency = min_t(psched_time_t, PSCHED_NS2TICKS(q->latency), UINT_MAX); - qopt.jitter = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->jitter), + qopt.jitter = min_t(psched_time_t, PSCHED_NS2TICKS(q->jitter), UINT_MAX); qopt.limit = q->limit; qopt.loss = q->loss; -- 2.35.1