Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2299925pxb; Fri, 5 Feb 2021 14:18:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsWEFylQOPXl1kp44Aiik1vZUrvXfhCvwJS17l7Wn6YNWk+X7vrrp8P60zf6FZyqE3oLBS X-Received: by 2002:a17:906:2407:: with SMTP id z7mr6172559eja.219.1612563497682; Fri, 05 Feb 2021 14:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612563497; cv=none; d=google.com; s=arc-20160816; b=VDRBpCQFiqKP3uzEHlPY/nWwtu1nFu7NmSew5wb5pp1F7lRxFaKwAA8ebPlkGdiD2h Qj90TIgzelaX5yCg4lXxajF3GFyjxIW5apaUOR3Up8e6KtNwDwkovmYfNmPH57IXeuc2 v0uM7hrZZxz4GrB5W037uIGhoN3vcyUPHp8nfN/LlTkdNklGSaDwobl33MMEp3T/l4Xr mmjl9UpT8PrJVQ/Woqa3BrnZv4/ZFnk/m/J5C4HYntPFVpEonelFgVM8drP28woix3gq hW8eF8jViFp2nDT7kL1HTlpgqqN46rRwp1T9khCr4Yzz8RvVWc6wVsjKPmq8+ILTFC1S 7F6A== 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=IfQzWxkqqqOpou0Izk8TbwwENFvcTe2V+sz+j717bL4=; b=ZV3s4KzLKQXR7lHfPR+StAVnTj8sIgUbmZeOCR3XuFUAvU2QgTKLeoTxNQQXe5QtfQ SW6vk5zwITLnNitkTppwAMWWQnREQJQZbacHmnfXfQns3ruPCPx0J7WdrQi8eihatgud SUuq3KzNqzJkYOhdKUCFJ9KJ6A26ecWYlxM6HDDxnX2f0fBZprxgJ/ypESv/l2DjcYHR av0FIg5IRTcXHLH0Y3C6qO+aJQNhzi3IsEkPejqjfYilEGhRezGL7jYt2FQ/jdCLD1LJ VpgSWNZgk7KWt38nVHXoXoK9DfAnzn2+h3FuAe7pAW8WRYq3fn63ZMHFHRJLOYWsqX1D jXwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s5HGmJe8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si7486626eds.167.2021.02.05.14.17.52; Fri, 05 Feb 2021 14:18:17 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s5HGmJe8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232787AbhBEWQv (ORCPT + 99 others); Fri, 5 Feb 2021 17:16:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:44990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232939AbhBEO5T (ORCPT ); Fri, 5 Feb 2021 09:57:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BC1FD650C2; Fri, 5 Feb 2021 14:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534490; bh=tl6keZasIZ9WS7JDVz0bg5JBs9ZZu9ZqJ3FJaEyrbRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s5HGmJe8j0goonw/B0il0FPlk+G+quXASQ8a7dsokZa1gIyJzhS5e7bgS0WYyFaG4 6O+voC08T+29CoDlflqD1XO/yS4TQF8pQdAuHmhgp8bVtuwHmhuwnc66quWzlFxmdA w/yNmf3gcc2Wbce6extbsvQKo9ASAUqGHExzrGDA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , Jakub Kicinski , Sudip Mukherjee Subject: [PATCH 4.14 05/15] net_sched: gen_estimator: support large ewma log Date: Fri, 5 Feb 2021 15:08:50 +0100 Message-Id: <20210205140649.942435794@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140649.733510103@linuxfoundation.org> References: <20210205140649.733510103@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet commit dd5e073381f2ada3630f36be42833c6e9c78b75e upstream syzbot report reminded us that very big ewma_log were supported in the past, even if they made litle sense. tc qdisc replace dev xxx root est 1sec 131072sec ... While fixing the bug, also add boundary checks for ewma_log, in line with range supported by iproute2. UBSAN: shift-out-of-bounds in net/core/gen_estimator.c:83:38 shift exponent -1 is negative CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.10.0-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:79 [inline] dump_stack+0x107/0x163 lib/dump_stack.c:120 ubsan_epilogue+0xb/0x5a lib/ubsan.c:148 __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x181 lib/ubsan.c:395 est_timer.cold+0xbb/0x12d net/core/gen_estimator.c:83 call_timer_fn+0x1a5/0x710 kernel/time/timer.c:1417 expire_timers kernel/time/timer.c:1462 [inline] __run_timers.part.0+0x692/0xa80 kernel/time/timer.c:1731 __run_timers kernel/time/timer.c:1712 [inline] run_timer_softirq+0xb3/0x1d0 kernel/time/timer.c:1744 __do_softirq+0x2bc/0xa77 kernel/softirq.c:343 asm_call_irq_on_stack+0xf/0x20 __run_on_irqstack arch/x86/include/asm/irq_stack.h:26 [inline] run_on_irqstack_cond arch/x86/include/asm/irq_stack.h:77 [inline] do_softirq_own_stack+0xaa/0xd0 arch/x86/kernel/irq_64.c:77 invoke_softirq kernel/softirq.c:226 [inline] __irq_exit_rcu+0x17f/0x200 kernel/softirq.c:420 irq_exit_rcu+0x5/0x20 kernel/softirq.c:432 sysvec_apic_timer_interrupt+0x4d/0x100 arch/x86/kernel/apic/apic.c:1096 asm_sysvec_apic_timer_interrupt+0x12/0x20 arch/x86/include/asm/idtentry.h:628 RIP: 0010:native_save_fl arch/x86/include/asm/irqflags.h:29 [inline] RIP: 0010:arch_local_save_flags arch/x86/include/asm/irqflags.h:79 [inline] RIP: 0010:arch_irqs_disabled arch/x86/include/asm/irqflags.h:169 [inline] RIP: 0010:acpi_safe_halt drivers/acpi/processor_idle.c:111 [inline] RIP: 0010:acpi_idle_do_entry+0x1c9/0x250 drivers/acpi/processor_idle.c:516 Fixes: 1c0d32fde5bd ("net_sched: gen_estimator: complete rewrite of rate estimators") Signed-off-by: Eric Dumazet Reported-by: syzbot Link: https://lore.kernel.org/r/20210114181929.1717985-1-eric.dumazet@gmail.com Signed-off-by: Jakub Kicinski [sudip: adjust context] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- net/core/gen_estimator.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/net/core/gen_estimator.c +++ b/net/core/gen_estimator.c @@ -84,11 +84,11 @@ static void est_timer(unsigned long arg) u64 rate, brate; est_fetch_counters(est, &b); - brate = (b.bytes - est->last_bytes) << (10 - est->ewma_log - est->intvl_log); - brate -= (est->avbps >> est->ewma_log); + brate = (b.bytes - est->last_bytes) << (10 - est->intvl_log); + brate = (brate >> est->ewma_log) - (est->avbps >> est->ewma_log); - rate = (u64)(b.packets - est->last_packets) << (10 - est->ewma_log - est->intvl_log); - rate -= (est->avpps >> est->ewma_log); + rate = (u64)(b.packets - est->last_packets) << (10 - est->intvl_log); + rate = (rate >> est->ewma_log) - (est->avpps >> est->ewma_log); write_seqcount_begin(&est->seq); est->avbps += brate; @@ -147,6 +147,9 @@ int gen_new_estimator(struct gnet_stats_ if (parm->interval < -2 || parm->interval > 3) return -EINVAL; + if (parm->ewma_log == 0 || parm->ewma_log >= 31) + return -EINVAL; + est = kzalloc(sizeof(*est), GFP_KERNEL); if (!est) return -ENOBUFS;