From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.bufferbloat.net (Postfix) with ESMTPS id 87C3A3B29D for ; Tue, 3 Sep 2024 12:09:42 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725379782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+vEL9t9N3TjzDKFfGVpcEH/htsU0bsy4GSN4Thmrm6E=; b=cP3pd9aJDW/O/0jFVRgCDC2edcxmr9S43vrFrwpi1IOUpN4FzhSYXEUmBwPzFRI5eh5iLc UE3rclVdQUbtZ+EVtfg9Rybj3h3oj843ik9Ms4RxsQ8xA4nWom+QHjtXZCKM+qsT5somrc UsjrzhRfRjBaArcvwbWJVAfPyuTJoZk= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-hjBdLcQoPFWJRJ6Sei1kiw-1; Tue, 03 Sep 2024 12:09:40 -0400 X-MC-Unique: hjBdLcQoPFWJRJ6Sei1kiw-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2f3f61b42c2so64968341fa.3 for ; Tue, 03 Sep 2024 09:09:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725379779; x=1725984579; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+vEL9t9N3TjzDKFfGVpcEH/htsU0bsy4GSN4Thmrm6E=; b=Dr8g7Z8FLU6wgd1epGA31r7rdi68aS3lbd7cwBM1rKu9v4KsPTl0WSZSF0Y10tRxyr YoBkkdRM5t/F8pGQ0EV0PzzZTXmJxsKF4QZmzKOj5U7OQSesCJ8zgbZtGtkzJmTJlSXH b/LvF3FlXzaN6UN4TVLErtGSRU7gvYNXU44RXKdMYa3jYX8ZRl3nToZi4mdeW3EQnbAe hWjyJsZ34JSOZFHoN+YWGTwHrm5BR71RfPlRJNSJTcgmF89kio7Ar4UG2+5z1i+Mw9ac HvZTamqaNklT6gOg2Mj17WWaj16VmOwSBJk6ntAmtbmZOuu20EPlso/PM24dSfUtimih dVOQ== X-Forwarded-Encrypted: i=1; AJvYcCWV6wwX5kRuMuDnLVAiLDt1TKezdySG+TG8K+IgPJNSLF0U3iTQuppgHysQahCU8Y7ijb63@lists.bufferbloat.net X-Gm-Message-State: AOJu0YyLlttwoovkJCW8G86yKC7a8f99fYRlvGlEzi0LfKrBipnGxdEq cqj5bdoUVEvUCzE60c0qWnIAXpH22Le71o032/wde9t30+9JkLu5iBePvWYUTzzfA/WzHp2ZISt J6H/+RFQkjNtsIBG6w3wDujpbl0pTlAeMC98nhzp8lEzNJ99WDZDxqAfP8DE= X-Received: by 2002:a05:651c:19a3:b0:2ef:c8a1:ff4 with SMTP id 38308e7fff4ca-2f6105c49a9mr156218331fa.7.1725379779289; Tue, 03 Sep 2024 09:09:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHM6IKnpjCa0SnPQDJqUDSYbdjdv3ACYWXRRNarHq2mh9lv5GtfRZskmFFlzTcDySivB4h63w== X-Received: by 2002:a05:651c:19a3:b0:2ef:c8a1:ff4 with SMTP id 38308e7fff4ca-2f6105c49a9mr156217921fa.7.1725379778590; Tue, 03 Sep 2024 09:09:38 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989233403sm696395866b.212.2024.09.03.09.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:09:38 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id DA5BA14AE5EC; Tue, 03 Sep 2024 18:09:36 +0200 (CEST) From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= To: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Jamal Hadi Salim , Cong Wang , Jiri Pirko , George Amanakis , "David S. Miller" Cc: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , syzbot+7fe7b81d602cc1e6b94d@syzkaller.appspotmail.com, Eric Dumazet , Jakub Kicinski , Paolo Abeni , cake@lists.bufferbloat.net, netdev@vger.kernel.org Date: Tue, 3 Sep 2024 18:08:45 +0200 Message-ID: <20240903160846.20909-1-toke@redhat.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Cake] [PATCH net] sched: sch_cake: fix bulk flow accounting logic for host fairness X-BeenThere: cake@lists.bufferbloat.net X-Mailman-Version: 2.1.20 Precedence: list List-Id: Cake - FQ_codel the next generation List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Sep 2024 16:09:42 -0000 In sch_cake, we keep track of the count of active bulk flows per host, when running in dst/src host fairness mode, which is used as the round-robin weight when iterating through flows. The count of active bulk flows is updated whenever a flow changes state. This has a peculiar interaction with the hash collision handling: when a hash collision occurs (after the set-associative hashing), the state of the hash bucket is simply updated to match the new packet that collided, and if host fairness is enabled, that also means assigning new per-host state to the flow. For this reason, the bulk flow counters of the host(s) assigned to the flow are decremented, before new state is assigned (and the counters, which may not belong to the same host anymore, are incremented again). Back when this code was introduced, the host fairness mode was always enabled, so the decrement was unconditional. When the configuration flags were introduced the *increment* was made conditional, but the *decrement* was not. Which of course can lead to a spurious decrement (and associated wrap-around to U16_MAX). AFAICT, when host fairness is disabled, the decrement and wrap-around happens as soon as a hash collision occurs (which is not that common in itself, due to the set-associative hashing). However, in most cases this is harmless, as the value is only used when host fairness mode is enabled. So in order to trigger an array overflow, sch_cake has to first be configured with host fairness disabled, and while running in this mode, a hash collision has to occur to cause the overflow. Then, the qdisc has to be reconfigured to enable host fairness, which leads to the array out-of-bounds because the wrapped-around value is retained and used as an array index. It seems that syzbot managed to trigger this, which is quite impressive in its own right. This patch fixes the issue by introducing the same conditional check on decrement as is used on increment. The original bug predates the upstreaming of cake, but the commit listed in the Fixes tag touched that code, meaning that this patch won't apply before that. Fixes: 712639929912 ("sch_cake: Make the dual modes fairer") Reported-by: syzbot+7fe7b81d602cc1e6b94d@syzkaller.appspotmail.com Signed-off-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 9602dafe32e6..d2f49db70523 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -786,12 +786,15 @@ static u32 cake_hash(struct cake_tin_data *q, const struct sk_buff *skb, * queue, accept the collision, update the host tags. */ q->way_collisions++; - if (q->flows[outer_hash + k].set == CAKE_SET_BULK) { - q->hosts[q->flows[reduced_hash].srchost].srchost_bulk_flow_count--; - q->hosts[q->flows[reduced_hash].dsthost].dsthost_bulk_flow_count--; - } allocate_src = cake_dsrc(flow_mode); allocate_dst = cake_ddst(flow_mode); + + if (q->flows[outer_hash + k].set == CAKE_SET_BULK) { + if (allocate_src) + q->hosts[q->flows[reduced_hash].srchost].srchost_bulk_flow_count--; + if (allocate_dst) + q->hosts[q->flows[reduced_hash].dsthost].dsthost_bulk_flow_count--; + } found: /* reserve queue for future packets in same flow */ reduced_hash = outer_hash + k; -- 2.46.0