Message ID | 20180826231332.2491-10-erosca@de.adit-jv.com |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show
Return-Path: <u-boot-bounces@lists.denx.de> X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=<UNKNOWN>) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="X0CgbJ34"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41z9xK3Td2z9ryt for <incoming@patchwork.ozlabs.org>; Mon, 27 Aug 2018 09:20:53 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 12A17C21DFA; Sun, 26 Aug 2018 23:17:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BE424C21DD7; Sun, 26 Aug 2018 23:17:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8706CC21DFF; Sun, 26 Aug 2018 23:16:32 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by lists.denx.de (Postfix) with ESMTPS id 0BE2EC21C8B for <u-boot@lists.denx.de>; Sun, 26 Aug 2018 23:16:29 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id o18-v6so6613213wmc.0 for <u-boot@lists.denx.de>; Sun, 26 Aug 2018 16:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LjHOjUdGY/DQ/mIKlWl6ookE/Elnmsv4AKAXJZB+uu0=; b=X0CgbJ34zVQO+w/sKQ8oS6VtW2965PjHyDEvmzy3jqSVl0aqs/BX0a9sw+rBar5zQc R+GzQTMp9k6Y98wp+xkGNu60m71q5Azratg2272BZHxgq3tZrqnPFEquMOrqwMhVPAgp 4VGuQW0HuyV03eBGuXCb75IsVS9zhnkHbTPTB1yvP2cltt/i0F3gq2junokFhpqp9bDk 31rJnfaZkx6VuPThLd7d341R88MbqNiTn8A3nYJY3MSW4CRzF1+AtOApdvxq0z0rI7iG Pw1V6tzuYr/JxAb4u9BQJJKt/UL73AsWJgHB15K88Tpt08IPAkVfS65ynxE7Uv94tL5a BHDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LjHOjUdGY/DQ/mIKlWl6ookE/Elnmsv4AKAXJZB+uu0=; b=qkVTa2jPLO5wthA1P3wq7BUjRznu75tmrszvogoxOX+wY8RpJChvKbNTKkG222twbu JFFQASW+W8CiIAYZDn/GimlrRxHTBzQJftnD+F+dKV4cpjlRXnZaRMKayH3ty2o7FCZP 2yjZrTwi+L/U2pswqNuXDg4x6EO0d2qHl5vkzsxaOKSsVDt2JJrHDteCuTuSPGSerYnN dreg6UxWcHr1IYvfeJzpRTVVklHjAzJ0+N0vJ6uVQDXw5qvTLkcLGab6zpU/L7mmrci1 yWL7YyS3vgONIX9ywC4ZwJlplYtoreKRDNubpw2aNkcXglqEEw0X0VR18GqmBQBa6Ycr qNcA== X-Gm-Message-State: APzg51A9IUOi0wrBjkNYkcnjV2PhGRFo71x5LjVqrbOlQjvmNflG+i8c cKNRRLgTDMWOGyfLoEuGJpM= X-Google-Smtp-Source: ANB0VdasVIgNtDfW5NEd5OqAWE5WP7QZPoC5eXwznxs5V+o6g4cDf9DOAx1C3HnG4yZvQpHf2wz+0Q== X-Received: by 2002:a1c:cb4d:: with SMTP id b74-v6mr4442548wmg.123.1535325388726; Sun, 26 Aug 2018 16:16:28 -0700 (PDT) Received: from localhost.localdomain (ipb218f467.dynamic.kabel-deutschland.de. [178.24.244.103]) by smtp.gmail.com with ESMTPSA id e141-v6sm10828362wmd.32.2018.08.26.16.16.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Aug 2018 16:16:28 -0700 (PDT) From: Eugeniu Rosca <roscaeugeniu@gmail.com> X-Google-Original-From: Eugeniu Rosca <erosca@de.adit-jv.com> To: Tom Rini <trini@konsulko.com>, u-boot@lists.denx.de Date: Mon, 27 Aug 2018 01:13:27 +0200 Message-Id: <20180826231332.2491-10-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180826231332.2491-1-erosca@de.adit-jv.com> References: <20180826231332.2491-1-erosca@de.adit-jv.com> Cc: Eugeniu Rosca <roscaeugeniu@gmail.com>, Michal Simek <michal.simek@xilinx.com>, Eugeniu Rosca <erosca@de.adit-jv.com>, Diego Dorta <diego.dorta@nxp.com> Subject: [U-Boot] [PATCH v2 09/13] common.h: Fix signed shift overflow in cpumask_next() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion <u-boot.lists.denx.de> List-Unsubscribe: <https://lists.denx.de/options/u-boot>, <mailto:u-boot-request@lists.denx.de?subject=unsubscribe> List-Archive: <http://lists.denx.de/pipermail/u-boot/> List-Post: <mailto:u-boot@lists.denx.de> List-Help: <mailto:u-boot-request@lists.denx.de?subject=help> List-Subscribe: <https://lists.denx.de/listinfo/u-boot>, <mailto:u-boot-request@lists.denx.de?subject=subscribe> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" <u-boot-bounces@lists.denx.de> |
Series |
Import Undefined Behavior Sanitizer
|
expand
|
diff --git a/include/common.h b/include/common.h index 940161f1758b..5b92666d0e79 100644 --- a/include/common.h +++ b/include/common.h @@ -319,7 +319,7 @@ void trap_init (ulong); /* $(CPU)/cpu.c */ static inline int cpumask_next(int cpu, unsigned int mask) { - for (cpu++; !((1 << cpu) & mask); cpu++) + for (cpu++; (cpu < 31) && !((1UL << cpu) & mask); cpu++) ; return cpu;
Fix the following UBSAN report: ================================================================= UBSAN: Undefined behaviour in include/common.h:322:19 left shift of 1 by 31 places cannot be represented in type 'int' ================================================================= Steps to reproduce the above: * echo CONFIG_UBSAN=y >> configs/qemu-ppce500_defconfig * make ARCH=powerpc CROSS_COMPILE=/usr/bin/powerpc-linux-gnu- \ qemu-ppce500_defconfig all * qemu-system-ppc --version QEMU emulator version 2.5.0 (Debian 1:2.5+dfsg-5ubuntu10.31) * qemu-system-ppc -machine ppce500 -nographic -no-reboot -kernel u-boot It looks like cpumask_next() intentionally uses shift overflow in its for loop condition to break the loop. Relying on UB is not safe. Convert the numeric literal 1 to 1UL and limit its maximum shift index to 31. Fixes: fbb9ecf7493f ("powerpc/mp: add support for discontiguous cores") Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com> --- Changes in v2: - None. Newly pushed. --- include/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)