From patchwork Fri Sep 6 06:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 1981549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0QvS01Q5z1yhD for ; Fri, 6 Sep 2024 16:15:31 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smSFX-00064e-Q7; Fri, 06 Sep 2024 06:15:15 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smSFW-00064X-8e for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 06:15:14 +0000 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C197F3F45F for ; Fri, 6 Sep 2024 06:15:13 +0000 (UTC) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-714484a692dso3088914b3a.1 for ; Thu, 05 Sep 2024 23:15:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725603312; x=1726208112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vqS24340nYb0qJXpDKydXeynQWUZIeonv05u3afCEvs=; b=o5tT/zIct8Ba78UkncrBiSsdERWLaKz8yXtCMlsVQSIfZATt0CpUAhKxD/L0y+V4bP tOzzZwWgTAsk1JunP50GY0CpkSuvsuRab703VCvW5WYj4Yh384PrCD9EkeKHBivMNEJA 78pQiMm8zU44peA8CrRAahg67t34g1zJsZW9wbv7xWjxuScSeSfxXPQwbBX3MsttSMQE eMdlLtiCSiIh1hMAxJ8JepUZOK4XNMEUVm+QIJNNnsyTYvdK37LrH5aCtz+7E4mygUeR 1mZeWoz9CUw1pN9fHZ9uR0i2UrKe2vJm1mQwEieh7eov2SeDAOXyIgHdKuPnr77mVGWx ZBpg== X-Gm-Message-State: AOJu0Yz+GItOddeCFs5QXkG6glvCvSCepX1VY4UrpF+pJGwzWhaQ9jbt PbjvjotccFmSruTTriYIBqvdE1V1XR8A9kYf4JEFNG23LzobRoWy2ZiP5SGOOioPHiOWdSAgmXg C+NJihy1pGIbfFh8gF/gunod3SsC4pEshKEEswSOeOvXgcqYduvb+vWvwNwfKVPRhlEdjKHVqra 3VhyCXK1+b3A== X-Received: by 2002:a17:903:228c:b0:206:8eec:c085 with SMTP id d9443c01a7336-206ee92564fmr28964565ad.2.1725603312177; Thu, 05 Sep 2024 23:15:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELGEiIn2NjYMyK7uvOEEuwGf9Yg+CNAaXB4Lt7g76CzyTtqnwTaEd0Eb0DI6zKjuqj1kJ3NA== X-Received: by 2002:a17:903:228c:b0:206:8eec:c085 with SMTP id d9443c01a7336-206ee92564fmr28964115ad.2.1725603311521; Thu, 05 Sep 2024 23:15:11 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:30a0:3aa:ffce:68e4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae9558fdsm37279885ad.91.2024.09.05.23.15.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 23:15:11 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 0/1] CVE-2024-26885 Date: Fri, 6 Sep 2024 15:14:37 +0900 Message-ID: <20240906061449.734300-1-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" [Impact] bpf: Fix DEVMAP_HASH overflow check on 32-bit arches The devmap code allocates a number hash buckets equal to the next power of two of the max_entries value provided when creating the map. When rounding up to the next power of two, the 32-bit variable storing the number of buckets can overflow, and the code checks for overflow by checking if the truncated 32-bit value is equal to 0. However, on 32-bit arches the rounding up itself can overflow mid-way through, because it ends up doing a left-shift of 32 bits on an unsigned long value. If the size of an unsigned long is four bytes, this is undefined behaviour, so there is no guarantee that we'll end up with a nice and tidy 0-value at the end. Syzbot managed to turn this into a crash on arm32 by creating a DEVMAP_HASH with max_entries > 0x80000000 and then trying to update it. Fix this by moving the overflow check to before the rounding up operation. [Backport] There were conflicts due to missing commits: - commit 844f157f6c0a ("bpf: Eliminate rlimit-based memory accounting for devmap maps") - commit 96360004b862 ("xdp: Make devmap flush_list common for all map instances") and resolved these conflicts by adjusting contexts without merging them to avoid unnecessary changes to the code base. [Fix] Noble: not affected Jammy: fixed via stable Focal: Backport - adjusted contexts due to missing commits, see [Backport] Bionic: not affected Xenial: not affected Trusty: not affected [Test Case] Compile and boot tested. Also (stress) tested using the syzbot reproducer [1] on my local armhf focal qemu instance, with and without this backport, though it did not trigger the reported issue even without the backport, likely due to a compiler difference from syzbot (i.e. the original overflow checking seemed to work even without the backport). I've not investigated more into it, but still the test confirms the robustness of this backport. [1] https://syzkaller.appspot.com/bug?extid=8cd36f6b65f3cafd400a [Where problems could occur] This fix potentially affects 32-bit arches, an issue with this fix would cause underfined behaviour when creating a DEVMAP_HASH with max_entries greater than 0x80000000. Toke Høiland-Jørgensen (1): bpf: Fix DEVMAP_HASH overflow check on 32-bit arches kernel/bpf/devmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) Acked-by: Manuel Diewald Acked-by: Thibault Ferrante