From nobody Fri Sep 25 06:46:57 2026 Received: from mail-wm2-f12.google.com (mail-wm2-f12.google.com [74.125.225.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3A994A3F20 for ; Tue, 15 Sep 2026 21:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506917; cv=none; b=kxyrSSIz9R7DIkuRxafp+oUzExjSj6vjWFHlwdM8PFMRgEyHw1YQAfRB5APlSNYiib6KJuwtVqeguAnEqynUUlb47vzx/TjF+DpXK/cslOaqmTaCjxLbheri374+CqPZ0mIcKWSts++wFbW+04ZysxwvPVSnDCX7G1P7kfVhPhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506917; c=relaxed/simple; bh=P4GnjYvjDdXvVLPEMZ2Mvy6/y1ufQV2xiluJDL+kMZ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a8c+Z+1VO31j5xF5v+pVTL3DyLcXhNmchVWAslHizwJmA6LS/e1DjYAxGYfMOY2oKGg6RoDZxdIWmuzJ/ICIljzbRx4S+5DHzxPLpamzGzUL5bgPZFFne8F3AKRwqkw4nxdhehBp0cfqej2SHcIA/1NStNu14SXqBm42fWr6vCQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OLFnO8DN; arc=none smtp.client-ip=74.125.225.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OLFnO8DN" Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49b912d37b5so1752445e9.2 for ; Tue, 15 Sep 2026 14:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789506914; x=1790111714; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Pp18lNSpLvIszH6E7VlmBrpqKQlpHF+L0iP+RB9/Ozo=; b=OLFnO8DN88YVgI/pcWelaTakmEZ7LvizgCHvnEZ7wx3Pju5TQW6f5zSP3+/iVlm65F 1Udplu4vA9UkhaUG2Q8Bm6Km8ecanss3I5PKAGZKBlxeFl1az3b22Qw+o+PYzeiRsZK3 5kDQSGB2bbKPri2S0TiNRMgIJMkzSVgEjinnQNP7mF2xKLu9f1C3ZhdIEIyYCbNDD9qc sYgYs4C7S+quced2SdX3ErW7uZNz19UAZO739ne0bNL3EHlipjzMSQ5idW2iKIrXUsQ+ 1r9PjE9vsTiZ9TM9aevkR1ghOPmpjnWhZchEMJjndzd04Z2BxUSZWEQ5waD6o5dQ5wdr jSNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789506914; x=1790111714; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Pp18lNSpLvIszH6E7VlmBrpqKQlpHF+L0iP+RB9/Ozo=; b=JAOHAQjN7RndqX16SMuq0yhUNdp1VQklt1MeQrHjeiaGGKbTp3ZvCm8bJReYFe2f7L 4ognGbzI+u0ISIahme7YCB0rmM4wRuf9SR1nYyHO5kdwdbybMEUsvrrh+7XdnIZMmcdG GtLt+mSjNLqxlgEGtXk2UO0ydc4nvBhMF7zc0bj3i75D8QXUuK6xb72yHeXfw/2RQCtN no8I3J1RMcRvlggCvCzyrYgpOrl7RxhxflYblFJtMPSm0IEiN6iS/OYMZgozjzC03i2/ XbXuFVrys3Nh6zQPs0XujJrXOHYOLTgl7qbqU5FbnKFGjMXXvk/+1GM8hAF9s32sor2y wiUQ== X-Forwarded-Encrypted: i=1; AKwUvBysXlJzW/sO6Pckz4gErPK2hgQSmq+gfyrbelsegghVyMRL2i3s+3ZGlQrxT9Qr6nmg3JAbOIiq2ygMTjk=@vger.kernel.org X-Gm-Message-State: AFuF++lvtdjLufb4benoCzBPPrIhR02siglMVFOHakBXMcEBsuE6AGv+ PC/zs+0Lp5K3ruVewKMoxvXrDmIXSFOYlc0c8bUoDU4U9/qyVLwyuEJma4IEXAHE X-Gm-Gg: AYBFou1ovqCqN3qXg/swlpDTYpy9a8hk3wPrDFhpKrhbUAxz0rd2KfSdeQDyxVmQlDT 7tPWl9SKnf5hsxxlpYrR6Ub7k4EmbMi5GOrbgYttpv7G4dwOhDjTn3FNpx1wdy+lnpjOTawJ2As Ib1IHlhdUmJVgUExKPdNXWs4cQol5Lggv596sfIh7I+MoZgfyPnO6ROni6o7ONgBuUdVCiXWx12 jteclAsODigPF4zbO+LqgFEqWhphK7CslfY+W9r9+Sxw3TC4dGbFP5MCXWGBV1ZZqxmmEGcxYzK 39Ib1koFDg1TQrzl1gJuw+vbtrGs7HaT7yncpi2gamlIL/8wJLmUzkXgCz3j59KlHGWpx50XLWj dz5zt/+F/nD7wtcZti4wNChiI4gLW4Lt2lFxvQZL2usvImuGb9H/DwJEuHCuMW82ftYnzcuy0hq w2YoOXLPRdq3aiuNnnVXpC+WY0kQK25AqHxWBAkA1iCVzlcezyIQU8rcr6RJ5IpFemvQVdfSdER LIdi1btQE1Q6ZGqAtfHkziXzAqq6qg06sTy X-Received: by 2002:a05:600c:34c1:b0:49c:e3c3:5efd with SMTP id 5b1f17b1804b1-49e7a67e4d5mr228611075e9.9.1789506914033; Tue, 15 Sep 2026 14:15:14 -0700 (PDT) Received: from nixos-office ([2001:8a0:e962:d100:b3c:e4b2:2d5f:e949]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e83b1ba9bsm24804695e9.15.2026.09.15.14.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 14:15:13 -0700 (PDT) Sender: Julian Braha From: Julian Braha To: nathan@kernel.org, nsc@kernel.org Cc: nico@fluxnic.net, rdunlap@infradead.org, grahamr@qti.qualcomm.com, kees@kernel.org, pengpeng@iscas.ac.cn, vegard.nossum@oracle.com, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Julian Braha Subject: [PATCH v2 1/5] kconfig: promote invalid numeric reference from warning to error Date: Tue, 15 Sep 2026 22:15:04 +0100 Message-ID: <20260915211508.291790-2-julianbraha@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260915211508.291790-1-julianbraha@gmail.com> References: <20260915211508.291790-1-julianbraha@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Kconfig interpreter already warns if a numeric option attempts to use a non-numeric option (bool, tristate, or string) to set its value (for example, with a 'default' or 'range'). Since there is nowhere in the tree that attempts this, we can safely promote this check from warning to error. Assisted-by: LLM Signed-off-by: Julian Braha Reviewed-by: Nicolas Schier --- scripts/kconfig/lkc.h | 2 +- scripts/kconfig/menu.c | 39 ++++++---- scripts/kconfig/parser.y | 2 +- .../tests/err_num_non_numeric_ref/Kconfig | 75 +++++++++++++++++++ .../tests/err_num_non_numeric_ref/__init__.py | 9 +++ .../err_num_non_numeric_ref/expected_stderr | 14 ++++ 6 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/Kconfig create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/__init__.= py create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/expected_= stderr diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 7e6f6ca299cf..bbc99f75b416 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -89,7 +89,7 @@ struct property *menu_add_prompt(enum prop_type type, con= st char *prompt, struct expr *dep); void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *de= p); void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr = *dep); -void menu_finalize(void); +int menu_finalize(void); void menu_set_type(int type); =20 extern struct menu rootmenu; diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 9c079e92a9ed..99a57ce0fdc9 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -240,11 +240,12 @@ static int menu_validate_number(struct symbol *sym, s= truct symbol *sym2) (sym2->type =3D=3D S_UNKNOWN && sym_string_valid(sym, sym2->name)); } =20 -static void sym_check_prop(struct symbol *sym) +static int sym_check_prop(struct symbol *sym) { struct property *prop; struct symbol *sym2; char *use; + int errors =3D 0; =20 for (prop =3D sym->prop; prop; prop =3D prop->next) { switch (prop->type) { @@ -258,10 +259,13 @@ static void sym_check_prop(struct symbol *sym) break; sym2 =3D prop_get_symbol(prop); if (sym->type =3D=3D S_HEX || sym->type =3D=3D S_INT) { - if (!menu_validate_number(sym, sym2)) - prop_warn(prop, - "'%s': number is invalid", - sym->name); + if (!menu_validate_number(sym, sym2)) { + fprintf(stderr, + "%s:%d: error: '%s': number is invalid\n", + prop->filename, prop->lineno, + sym->name); + errors++; + } } if (sym_is_choice(sym)) { struct menu *choice =3D sym_get_choice_menu(sym2); @@ -293,21 +297,28 @@ static void sym_check_prop(struct symbol *sym) prop_warn(prop, "range is only allowed " "for int or hex symbols"); if (!menu_validate_number(sym, prop->expr->left.sym) || - !menu_validate_number(sym, prop->expr->right.sym)) - prop_warn(prop, "range is invalid"); + !menu_validate_number(sym, prop->expr->right.sym)) { + fprintf(stderr, + "%s:%d: error: range is invalid\n", + prop->filename, prop->lineno); + errors++; + } break; default: ; } } + + return errors; } =20 -static void _menu_finalize(struct menu *parent, bool inside_choice) +static int _menu_finalize(struct menu *parent, bool inside_choice) { struct menu *menu, *last_menu; struct symbol *sym; struct property *prop; struct expr *basedep, *dep, *dep2; + int errors =3D 0; =20 sym =3D parent->sym; if (parent->list) { @@ -393,7 +404,7 @@ static void _menu_finalize(struct menu *parent, bool in= side_choice) * moving on */ for (menu =3D parent->list; menu; menu =3D menu->next) - _menu_finalize(menu, sym && sym_is_choice(sym)); + errors +=3D _menu_finalize(menu, sym && sym_is_choice(sym)); } else if (!inside_choice && sym) { /* * Automatic submenu creation. If sym is a symbol and A, B, C, @@ -461,7 +472,7 @@ static void _menu_finalize(struct menu *parent, bool in= side_choice) } /* Superset, put in submenu */ next: - _menu_finalize(menu, false); + errors +=3D _menu_finalize(menu, false); menu->parent =3D parent; last_menu =3D menu; } @@ -519,14 +530,16 @@ static void _menu_finalize(struct menu *parent, bool = inside_choice) menu_warn(parent, "config symbol defined without type"); =20 /* Check properties connected to this symbol */ - sym_check_prop(sym); + errors +=3D sym_check_prop(sym); sym->flags |=3D SYMBOL_WARNED; } + + return errors; } =20 -void menu_finalize(void) +int menu_finalize(void) { - _menu_finalize(&rootmenu, false); + return _menu_finalize(&rootmenu, false); } =20 bool menu_has_prompt(const struct menu *menu) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 5fb6f07b6ad2..40ceb9908c6f 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -587,7 +587,7 @@ void conf_parse(const char *name) menu_add_prompt(P_MENU, "Main menu", NULL); } =20 - menu_finalize(); + yynerrs +=3D menu_finalize(); =20 menu_for_each_entry(menu) { struct menu *child; diff --git a/scripts/kconfig/tests/err_num_non_numeric_ref/Kconfig b/script= s/kconfig/tests/err_num_non_numeric_ref/Kconfig new file mode 100644 index 000000000000..0ca7a4a460f6 --- /dev/null +++ b/scripts/kconfig/tests/err_num_non_numeric_ref/Kconfig @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: GPL-2.0 +# Test non-numeric symbol references from numeric symbols + +config BOOL_SOURCE + bool + +config TRISTATE_SOURCE + tristate + +config STRING_SOURCE + string + +# Invalid int defaults + +config INT_DEFAULT_BOOL + int + default BOOL_SOURCE + +config INT_DEFAULT_TRISTATE + int + default TRISTATE_SOURCE + +config INT_DEFAULT_STRING + int + default STRING_SOURCE + +# Invalid hex defaults + +config HEX_DEFAULT_BOOL + hex + default BOOL_SOURCE + +config HEX_DEFAULT_TRISTATE + hex + default TRISTATE_SOURCE + +config HEX_DEFAULT_STRING + hex + default STRING_SOURCE + +# Invalid int ranges + +config INT_RANGE_BOOL + int + range BOOL_SOURCE 1 + +config INT_RANGE_TRISTATE + int + range TRISTATE_SOURCE 1 + +config INT_RANGE_STRING + int + range STRING_SOURCE 1 + +config INT_RANGE_MULTIPLE + int + range BOOL_SOURCE TRISTATE_SOURCE + +# Invalid hex ranges + +config HEX_RANGE_BOOL + hex + range BOOL_SOURCE 0x1 + +config HEX_RANGE_TRISTATE + hex + range TRISTATE_SOURCE 0x1 + +config HEX_RANGE_STRING + hex + range STRING_SOURCE 0x1 + +config HEX_RANGE_MULTIPLE + hex + range BOOL_SOURCE TRISTATE_SOURCE diff --git a/scripts/kconfig/tests/err_num_non_numeric_ref/__init__.py b/sc= ripts/kconfig/tests/err_num_non_numeric_ref/__init__.py new file mode 100644 index 000000000000..9632907abead --- /dev/null +++ b/scripts/kconfig/tests/err_num_non_numeric_ref/__init__.py @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +""" +Reject nonnumeric symbol references from int and hex properties. +""" + + +def test(conf): + assert conf.olddefconfig() =3D=3D 1 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr = b/scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr new file mode 100644 index 000000000000..4974ba2fcd9c --- /dev/null +++ b/scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr @@ -0,0 +1,14 @@ +Kconfig:17: error: 'INT_DEFAULT_BOOL': number is invalid +Kconfig:21: error: 'INT_DEFAULT_TRISTATE': number is invalid +Kconfig:25: error: 'INT_DEFAULT_STRING': number is invalid +Kconfig:31: error: 'HEX_DEFAULT_BOOL': number is invalid +Kconfig:35: error: 'HEX_DEFAULT_TRISTATE': number is invalid +Kconfig:39: error: 'HEX_DEFAULT_STRING': number is invalid +Kconfig:45: error: range is invalid +Kconfig:49: error: range is invalid +Kconfig:53: error: range is invalid +Kconfig:57: error: range is invalid +Kconfig:63: error: range is invalid +Kconfig:67: error: range is invalid +Kconfig:71: error: range is invalid +Kconfig:75: error: range is invalid --=20 2.55.0 From nobody Fri Sep 25 06:46:57 2026 Received: from mail-wm2-f12.google.com (mail-wm2-f12.google.com [74.125.225.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD7374AA402 for ; Tue, 15 Sep 2026 21:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506919; cv=none; b=pAx9vfiw3k9J4jm1LK7o3SBlhs7ZsO6jofRbxlR91ACl+j8ooHBINlNNgqw9YQydImAI1BghUPpVod8xaXkdg+IDKH7Iyo9CD7f/1y5uDCiKSaDk3tn9SAS/rYcFmdx7vTQnCdOdw1O7Jy49PPfbqmkBoBvqf/UwvZcMeOsnb3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506919; c=relaxed/simple; bh=3psxrsfWdIlR+uDQcWe+rgSTzb3QV8s1q2v5Lu0dofk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a9xHBYQA01Ys4nwQzYwwrzEoZeDutg2sGj2oLXlOXNwHECljcwyIHj9JaX3+3WrhOTU98cIGCD0pAuBr1uLoKvkqr5pUWhrvDiN+fHauj0iR5VmVQoO/SBmMqjXzs+I6/L/daPteVPVTyPqhhBib4JqZAYK2OPDjD9JEdX9K3CM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NkVpcoMT; arc=none smtp.client-ip=74.125.225.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NkVpcoMT" Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49d1ca5b0d6so1912485e9.0 for ; Tue, 15 Sep 2026 14:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789506916; x=1790111716; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to:content-type; bh=emUgjgJBLOzRZSL8qI4Q3Z9mtgFScVqVYtdaLTRXLjA=; b=NkVpcoMT+N5HyQ6biBkQcKc+aoYIOrVs0FI6mpfG0vUVoNrVbex1ERvKFpMaGH8o22 qxSdUUC1QenvGvCufQLqt5DTA4G4KF3JKi+XkX043NOCmBgnnUkX3UkQHec+08aeg6j4 /Zba6bxNyLbwJwT1BHFBF7geX1l4+5+eSjFIPO5DeDtwvBwl16rV3JIYtrx1dg0JVAfX Qo7m//VYVXLtSwnixEMrizfMa5iulA/IujVQbyFo20aFpxGi7ePZDv2sb6kDh1T7Wyj5 tIEh7Pk5jB4RmNjYk5jpAMJpN/8lz4zHWtYdQOETfn5Q6vpJ2rR0C5aFB60We/PprmoP 5/QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789506916; x=1790111716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=emUgjgJBLOzRZSL8qI4Q3Z9mtgFScVqVYtdaLTRXLjA=; b=VCC3429DHa3WTHOdQ7aSyGWm9liglarksLVNHxT/j1d0W1J7WP2tHVDNyVrhdbv1gU x7lbCbDmsW2RfPZwGnB/y3XiRiWWrQ9Yzo8c/sH+qFlcR93oN1p3jAtq362fuu5GIpq8 kaiwtr+VHjD8yWkNNEMP9WoP1F8XN1onspAfDZn4c+mw4wQ6dCjeITg9mkYW/nkBMwtM gjItSLtHA+UL+YY/35h+pXV+j6J+vK06mrUx2VJHYOwifIccE5JmoOaFKiYRfsnzzPCv pL2BDJ1GkD+dZHD4F2ZtXCoGECSIuQWaFNewf/4z2m7us3r/AnTL9AEb1wC0d2ikLCz0 tTuA== X-Forwarded-Encrypted: i=1; AKwUvBy32mIpGmUX3wNviJPOVLctvhaUjw6ioxLVy9vdt7Wfhk3RvW1bpbUH0JAzr5TKQ6xxag5nAlfI3w462Hk=@vger.kernel.org X-Gm-Message-State: AFuF++lA4pZVonAvAVEGTiAS0XObuVj/E+BgfAGOswbnea/YHy/i+e7L Rft6v5cEasBJZGLpThg/Yt7mS3s+JFSBJKqw9ePZPbyDtLANcqUxi6pt X-Gm-Gg: AYBFou3pPcuRhwRgxnQexE/WxtfVrTw4QwPuV0BlKxx48NBWaajBs6ik3dWi62dFA9x 9HNSQwl6OmXMU/k6h2iGasCD9nkHXd0OrjcUO+lYWbC8LNamq+j4g/3Zp+j+QP2S+EmqRT/OR3/ xYvc0OhNsr5wHjfritfNki7RbmGJmeDylYdx8+PvHJD5bM2jV4Bkvxkb8WoqqK27Lb251KvRpe+ tx6Pr5ROc0AjHPEsLU45Q6rG9QrCDzZkQBiIUV6CGGtTzZBcv2oxx51xu1Ax4rvAC4SdamEFBe5 zZztiLUGlLYL9Rnpj35DfQZpSLi+f+pZMcfzKk5BGujnNeu2983h3TZyEfN2WEQtLQdZ5OJ1wKt nYWUPkf+NBK8TWsaCChyseiV0f1GVaILzzPZaWRErhRZeuRSg5JGpdw9Gfy3UJkCLyKN1Fm86rf GWLx0JQ8sctBJEU2mheSBIVSHshpe8vJj1KYLeJwuOaJoq/afoPCwL6fB2teSzi6PwBPS2O7pJF g+W8i41Q1XlaOsT+USfPHV994tmfsU99a5/ X-Received: by 2002:a05:600c:c4a2:b0:49d:1842:f001 with SMTP id 5b1f17b1804b1-49e8224ff79mr37273785e9.14.1789506915874; Tue, 15 Sep 2026 14:15:15 -0700 (PDT) Received: from nixos-office ([2001:8a0:e962:d100:b3c:e4b2:2d5f:e949]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e83b1ba9bsm24804695e9.15.2026.09.15.14.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 14:15:15 -0700 (PDT) Sender: Julian Braha From: Julian Braha To: nathan@kernel.org, nsc@kernel.org Cc: nico@fluxnic.net, rdunlap@infradead.org, grahamr@qti.qualcomm.com, kees@kernel.org, pengpeng@iscas.ac.cn, vegard.nossum@oracle.com, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Julian Braha Subject: [PATCH v2 2/5] kconfig: check for out-of-bounds numeric constants Date: Tue, 15 Sep 2026 22:15:05 +0100 Message-ID: <20260915211508.291790-3-julianbraha@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260915211508.291790-1-julianbraha@gmail.com> References: <20260915211508.291790-1-julianbraha@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Kconfig interpreter internally represents constants as strings, then attempts to parse them as 64-bit signed integers for 'int' options, and 64-bit unsigned integers for 'hex' options. However, there is currently no check that the conversion succeeds, leading to failures when the values are actually used. For example: config LARGE_INT int default 10000000000000000000 config BUGGED_INT_COMPARISON bool default y if LARGE_INT < 2 Obviously 10000000000000000000 is larger than 2, but the Kconfig interpreter will fallback to comparing the two values with strcmp() after the numeric conversion fails, causing the first character, '1', to be compared with '2', and giving the wrong result. Since none of these out-of-bounds values are used as constants anywhere in the tree, we can already make these error out. Assisted-by: LLM Signed-off-by: Julian Braha Reviewed-by: Nicolas Schier --- scripts/kconfig/menu.c | 60 ++++++++++---- scripts/kconfig/tests/err_num_bounds/Kconfig | 79 +++++++++++++++++++ .../kconfig/tests/err_num_bounds/__init__.py | 12 +++ .../tests/err_num_bounds/expected_stderr | 10 +++ .../err_num_non_numeric_ref/expected_stderr | 30 +++---- 5 files changed, 160 insertions(+), 31 deletions(-) create mode 100644 scripts/kconfig/tests/err_num_bounds/Kconfig create mode 100644 scripts/kconfig/tests/err_num_bounds/__init__.py create mode 100644 scripts/kconfig/tests/err_num_bounds/expected_stderr diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 99a57ce0fdc9..ede791a2fe1b 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -4,6 +4,7 @@ */ =20 #include +#include #include #include #include @@ -234,10 +235,46 @@ void menu_add_symbol(enum prop_type type, struct symb= ol *sym, struct expr *dep) menu_add_prop(type, expr_alloc_symbol(sym), dep); } =20 -static int menu_validate_number(struct symbol *sym, struct symbol *sym2) +/* Validate the sym2 value for numeric sym. */ +static int menu_validate_number(struct symbol *sym, struct symbol *sym2, + const struct property *prop) { - return sym2->type =3D=3D S_INT || sym2->type =3D=3D S_HEX || - (sym2->type =3D=3D S_UNKNOWN && sym_string_valid(sym, sym2->name)); + const char *type_bounds; + + if (sym->type !=3D S_INT && sym->type !=3D S_HEX) + return 0; + + if (sym2->type =3D=3D S_INT || sym2->type =3D=3D S_HEX) + return 0; + + if (sym2->type !=3D S_UNKNOWN || + !sym_string_valid(sym, sym2->name)) { + fprintf(stderr, "%s:%d: error: '%s' is an invalid value for '%s'\n", + prop->filename, prop->lineno, sym2->name, + sym_type_name(sym->type)); + return 1; + } + + errno =3D 0; + if (sym->type =3D=3D S_INT) { + type_bounds =3D "64-bit signed integer"; + strtoll(sym2->name, NULL, 10); + } else { + /* hex */ + type_bounds =3D "64-bit unsigned integer"; + strtoull(sym2->name, NULL, 16); + } + + if (errno =3D=3D ERANGE) { + fprintf(stderr, + "%s:%d: error: %s constant '%s' is outside the %s bounds\n", + prop->filename, prop->lineno, sym_type_name(sym->type), + sym2->name, type_bounds); + + return 1; + } + + return 0; } =20 static int sym_check_prop(struct symbol *sym) @@ -259,13 +296,7 @@ static int sym_check_prop(struct symbol *sym) break; sym2 =3D prop_get_symbol(prop); if (sym->type =3D=3D S_HEX || sym->type =3D=3D S_INT) { - if (!menu_validate_number(sym, sym2)) { - fprintf(stderr, - "%s:%d: error: '%s': number is invalid\n", - prop->filename, prop->lineno, - sym->name); - errors++; - } + errors +=3D menu_validate_number(sym, sym2, prop); } if (sym_is_choice(sym)) { struct menu *choice =3D sym_get_choice_menu(sym2); @@ -296,13 +327,8 @@ static int sym_check_prop(struct symbol *sym) if (sym->type !=3D S_INT && sym->type !=3D S_HEX) prop_warn(prop, "range is only allowed " "for int or hex symbols"); - if (!menu_validate_number(sym, prop->expr->left.sym) || - !menu_validate_number(sym, prop->expr->right.sym)) { - fprintf(stderr, - "%s:%d: error: range is invalid\n", - prop->filename, prop->lineno); - errors++; - } + errors +=3D menu_validate_number(sym, prop->expr->left.sym, prop); + errors +=3D menu_validate_number(sym, prop->expr->right.sym, prop); break; default: ; diff --git a/scripts/kconfig/tests/err_num_bounds/Kconfig b/scripts/kconfig= /tests/err_num_bounds/Kconfig new file mode 100644 index 000000000000..c439366c03b6 --- /dev/null +++ b/scripts/kconfig/tests/err_num_bounds/Kconfig @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: GPL-2.0 +# Test bounds checks for 'int' and 'hex' constants + +config INT_SOURCE + int + +config HEX_SOURCE + hex + +config BOOL_SOURCE + bool + +# Valid values at the limits of the type + +config INT_MIN + int + default -9223372036854775808 + +config INT_MAX + int + default 9223372036854775807 + +config HEX_MIN + hex + default 0x0 + +config HEX_MAX + hex + default 0xffffffffffffffff + +config INT_RANGE_LIMITS + int + range -9223372036854775808 9223372036854775807 + +config HEX_RANGE_LIMITS + hex + range 0 0xffffffffffffffff + +config INT_FROM_INT + int + default INT_SOURCE + +config HEX_FROM_HEX + hex + default HEX_SOURCE + +# Constants outside the bounds + +config INT_DEFAULT_TOO_HIGH + int + default 10000000000000000000 + +config INT_DEFAULT_TOO_LOW + int + default -9223372036854775809 + +config INT_RANGE_TOO_HIGH + int + range 0 10000000000000000000 + +config INT_RANGE_TOO_LOW + int + range -10000000000000000000 0 + +config INT_RANGE_BOTH_OUTSIDE + int + range -9223372036854775809 10000000000000000000 + +config HEX_DEFAULT_TOO_HIGH + hex + default 0x10000000000000000 + +config HEX_RANGE_TOO_HIGH + hex + range 0 0x10000000000000000 + +config HEX_RANGE_BOTH_TOO_HIGH + hex + range 0x10000000000000000 0x20000000000000000 diff --git a/scripts/kconfig/tests/err_num_bounds/__init__.py b/scripts/kco= nfig/tests/err_num_bounds/__init__.py new file mode 100644 index 000000000000..72ac6aa24491 --- /dev/null +++ b/scripts/kconfig/tests/err_num_bounds/__init__.py @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +""" +Detect constants outside the 'int' and 'hex' bounds. + +An int constant must fit in a signed 64-bit integer, and a hex constant mu= st +fit in an unsigned 64-bit integer. +""" + + +def test(conf): + assert conf.olddefconfig() =3D=3D 1 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/err_num_bounds/expected_stderr b/scripts= /kconfig/tests/err_num_bounds/expected_stderr new file mode 100644 index 000000000000..3f06e13359ef --- /dev/null +++ b/scripts/kconfig/tests/err_num_bounds/expected_stderr @@ -0,0 +1,10 @@ +Kconfig:51: error: integer constant '10000000000000000000' is outside the = 64-bit signed integer bounds +Kconfig:55: error: integer constant '-9223372036854775809' is outside the = 64-bit signed integer bounds +Kconfig:59: error: integer constant '10000000000000000000' is outside the = 64-bit signed integer bounds +Kconfig:63: error: integer constant '-10000000000000000000' is outside the= 64-bit signed integer bounds +Kconfig:67: error: integer constant '-9223372036854775809' is outside the = 64-bit signed integer bounds +Kconfig:67: error: integer constant '10000000000000000000' is outside the = 64-bit signed integer bounds +Kconfig:71: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned integer bounds +Kconfig:75: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned integer bounds +Kconfig:79: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned integer bounds +Kconfig:79: error: hex constant '0x20000000000000000' is outside the 64-bi= t unsigned integer bounds diff --git a/scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr = b/scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr index 4974ba2fcd9c..005f855ecbdd 100644 --- a/scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr +++ b/scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr @@ -1,14 +1,16 @@ -Kconfig:17: error: 'INT_DEFAULT_BOOL': number is invalid -Kconfig:21: error: 'INT_DEFAULT_TRISTATE': number is invalid -Kconfig:25: error: 'INT_DEFAULT_STRING': number is invalid -Kconfig:31: error: 'HEX_DEFAULT_BOOL': number is invalid -Kconfig:35: error: 'HEX_DEFAULT_TRISTATE': number is invalid -Kconfig:39: error: 'HEX_DEFAULT_STRING': number is invalid -Kconfig:45: error: range is invalid -Kconfig:49: error: range is invalid -Kconfig:53: error: range is invalid -Kconfig:57: error: range is invalid -Kconfig:63: error: range is invalid -Kconfig:67: error: range is invalid -Kconfig:71: error: range is invalid -Kconfig:75: error: range is invalid +Kconfig:17: error: 'BOOL_SOURCE' is an invalid value for 'integer' +Kconfig:21: error: 'TRISTATE_SOURCE' is an invalid value for 'integer' +Kconfig:25: error: 'STRING_SOURCE' is an invalid value for 'integer' +Kconfig:31: error: 'BOOL_SOURCE' is an invalid value for 'hex' +Kconfig:35: error: 'TRISTATE_SOURCE' is an invalid value for 'hex' +Kconfig:39: error: 'STRING_SOURCE' is an invalid value for 'hex' +Kconfig:45: error: 'BOOL_SOURCE' is an invalid value for 'integer' +Kconfig:49: error: 'TRISTATE_SOURCE' is an invalid value for 'integer' +Kconfig:53: error: 'STRING_SOURCE' is an invalid value for 'integer' +Kconfig:57: error: 'BOOL_SOURCE' is an invalid value for 'integer' +Kconfig:57: error: 'TRISTATE_SOURCE' is an invalid value for 'integer' +Kconfig:63: error: 'BOOL_SOURCE' is an invalid value for 'hex' +Kconfig:67: error: 'TRISTATE_SOURCE' is an invalid value for 'hex' +Kconfig:71: error: 'STRING_SOURCE' is an invalid value for 'hex' +Kconfig:75: error: 'BOOL_SOURCE' is an invalid value for 'hex' +Kconfig:75: error: 'TRISTATE_SOURCE' is an invalid value for 'hex' --=20 2.55.0 From nobody Fri Sep 25 06:46:57 2026 Received: from mail-wm2-f13.google.com (mail-wm2-f13.google.com [74.125.225.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF9784A3F25 for ; Tue, 15 Sep 2026 21:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506921; cv=none; b=ba0yb2qZvY+UQGpiT7mrcAEIzRgpEsohvIhiBZomqXm5h1qd6Qel5j/4vqxZxcH4A3UOOnodmdIMBJmMKRb41yGMpWvn9vkBKtDHYJaLmyQZHspj2R9azkTZWc2TDV+A2n1tjXVugYewJQmZXs6Ki3EVFBp2oM0INNI5Z6zxQjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506921; c=relaxed/simple; bh=R9MpoArkbHIg3SaeDJtk9ZD6FPf22CQrSgvl16eoetE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sK2R7d99BhmcP+d12rOOwZaobwc8C7Lghb9euJexa+tFdnldY40cWFlG9U+MoEwZNza7nlT6LJJnOGfDm4uWqy3abLSVCtdekUbwT2jg6qxbSzmamG++46uj0rg5ARFVBQtf7ccKE3DWBdZj3RXc3M3Ij5CuXDd2I45IhbkenAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PJJG6y4f; arc=none smtp.client-ip=74.125.225.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PJJG6y4f" Received: by mail-wm2-f13.google.com with SMTP id 5b1f17b1804b1-49cc9f581c4so1011675e9.0 for ; Tue, 15 Sep 2026 14:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789506918; x=1790111718; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7p1LDWrlveId4m1yDuiZZyPI5rbWZo/B9PJF7MZPH1U=; b=PJJG6y4fB8XLSEZtepYT+qMXiC+5qehbjZskCsb/DaNZVGbSlXBN4rT6AoZ39Fyy+F ro1vw9vDw/iHWcIt8FEF3qYAwP/lEPGxfUQjVkC8Cx7PKVqDx/jKpJkzwW3pl6CgPkBZ ZO/smA/DH39qJRpxeDWCdnd6jMeSPeYuafXCi8fj2mNXdufcOj4cM3llgDm82XoXjM39 KhDx7gF+dPXsJUd/8XOWsAQjK7UIMmOnZbX5EABKKUPYppOSK6Pr5D1itXU/lD0T1wU0 /iGfFZRP+PYElhU+u/zd4QW+E8L3tW1PABiK+/GVqFlnkosaDO4nutn+FdnzKsUpzHwC TIvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789506918; x=1790111718; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7p1LDWrlveId4m1yDuiZZyPI5rbWZo/B9PJF7MZPH1U=; b=sVNSi5cBYzNbHseAv+WP5JzYdp2eX7Oal3fVdAp+xJsrcJhkovbbBqK2+d/LgH9KRC yS3mrBm06TezE+8aOg5CUI5pjlgimjjVBaNlulAo+oy8OwLZ4d7rPZ+nbuEu1/SJL/Lp 85OMdXjT/yDapPqwCKMzCFv6AIbICVKBBnmhQ/NNFfrQx6eLJxY+JDGjuS9ezqJX9Itk pwCaORMfd3rY+GlOGItuJpWxLsq+bTj2FGD8MT5Rhq8Z3lyYcsWwOBLohb6Up8zbnZ1Y h3HhFz5UlRgFxj9rojL+ijfuLj5IiyNL/3fFd+MCU+oG4UZe8RyN7KHEe91fPvon/2b9 1ULA== X-Forwarded-Encrypted: i=1; AKwUvBzYvX9snn9iGakD2zYzH5UVwpLUXDALy6HjJ94VNE70tRL1csvJqTUEcXhiQHRGq+32Wz/1C5J46VpiCRo=@vger.kernel.org X-Gm-Message-State: AFuF++nCOaCO1NT3+gJN+rLUzsy6rzBa18hJUDoh1a0JZ7KTQXytfbOW m462oJhf3s68hlUb5oyM9Ew46oN1QLezbmrckUdi59xeG0hpLKhGpL92 X-Gm-Gg: AYBFou3WmwvT1Vefs6HTXROnwCC42VPxzI0nD0FdEY0t1oovl2r9tdaVCY55SDyReGJ hNZrRsYvpQ/IUQ9IxpStI4jQjpI26kRIoVvFBXaQUQJK4X7nbRzayeHy9NeZjNbQsnGZBz3A3vc HJAb5XhwH/FZbJkOc2+Sv01rT9YOHHBGhq5/tmd/DwilgmBke41lHxIOtRkCIgJ3aRLaM2PWJzV VIVqu959R7L2Zz8C62Z/ukWFWo0mmhSVD6A5NpR3PR08E2PIoIfSyRoDcJapDAsfukZOWHJKzaH VcjuKKFpobfyJhLNulMIYsJWseo6fKZsCQOL+nxuh3euwSlh1GJIdyKPUm1HsmNimqv05OiYpWe AGd95CGMy1JWvVpAKYoH+Ucgg7pFJqoPJUwv/zCbPgZ4dAFf2osapn8KmecRT77j43toAzkMVTa ySqrahfAhgnBeIZD82RdFsXX+np1LPTTI8xhp0HNiypN3xNNmmeL0kfRmN2tX8ZH8jGez5REwtF 9YRQ6x9La3Fx7UUXEuaPumyIsn2ft9qVhYg X-Received: by 2002:a05:600c:4f08:b0:49e:63cc:6324 with SMTP id 5b1f17b1804b1-49e9666ba5emr59375e9.6.1789506917972; Tue, 15 Sep 2026 14:15:17 -0700 (PDT) Received: from nixos-office ([2001:8a0:e962:d100:b3c:e4b2:2d5f:e949]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e83b1ba9bsm24804695e9.15.2026.09.15.14.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 14:15:17 -0700 (PDT) Sender: Julian Braha From: Julian Braha To: nathan@kernel.org, nsc@kernel.org Cc: nico@fluxnic.net, rdunlap@infradead.org, grahamr@qti.qualcomm.com, kees@kernel.org, pengpeng@iscas.ac.cn, vegard.nossum@oracle.com, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Julian Braha Subject: [PATCH v2 3/5] kconfig: check for hex and int mismatches Date: Tue, 15 Sep 2026 22:15:06 +0100 Message-ID: <20260915211508.291790-4-julianbraha@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260915211508.291790-1-julianbraha@gmail.com> References: <20260915211508.291790-1-julianbraha@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Using a numeric option of one type (e.g. 'int') to determine the value of a different numeric type (e.g. 'hex') currently fails silently in various ways if attempted, because the underlying string representation is naively reused. Example 1: config I int default -1 config HEX_DEFAULT_INT hex default I Here, HEX_DEFAULT_INT actually gets set to '0x-1', which is of course not a valid hex value. Example 2: config H hex default A config INT_DEFAULT_HEX int default H Here, INT_DEFAULT_HEX actually gets set to 'A', without even converting into the base-10 equivalent of 10. This value, 'A', is otherwise a rejected int value if entered in the frontend, or read in from an existing .config file. These int-hex mismatches currently do not appear anywhere in the tree, so it is already safe to make these error out. Assisted-by: LLM Signed-off-by: Julian Braha Reviewed-by: Nicolas Schier --- scripts/kconfig/menu.c | 2 +- .../kconfig/tests/err_num_mismatch/Kconfig | 38 +++++++++++++++++++ .../tests/err_num_mismatch/__init__.py | 9 +++++ .../tests/err_num_mismatch/expected_stderr | 4 ++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 scripts/kconfig/tests/err_num_mismatch/Kconfig create mode 100644 scripts/kconfig/tests/err_num_mismatch/__init__.py create mode 100644 scripts/kconfig/tests/err_num_mismatch/expected_stderr diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index ede791a2fe1b..2d8b0c65ce1e 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -244,7 +244,7 @@ static int menu_validate_number(struct symbol *sym, str= uct symbol *sym2, if (sym->type !=3D S_INT && sym->type !=3D S_HEX) return 0; =20 - if (sym2->type =3D=3D S_INT || sym2->type =3D=3D S_HEX) + if (sym2->type =3D=3D sym->type) return 0; =20 if (sym2->type !=3D S_UNKNOWN || diff --git a/scripts/kconfig/tests/err_num_mismatch/Kconfig b/scripts/kconf= ig/tests/err_num_mismatch/Kconfig new file mode 100644 index 000000000000..8406f3bb6419 --- /dev/null +++ b/scripts/kconfig/tests/err_num_mismatch/Kconfig @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0 +# Test 'int' and 'hex' symbols that reference each other + +config INT_SOURCE + int + +config HEX_SOURCE + hex + +# 'hex' reference from 'int' + +config INT_DEFAULT_HEX + int + default HEX_SOURCE + +config INT_RANGE_HEX + int + range HEX_SOURCE 1 + +# A hex symbol must not reference an int symbol + +config HEX_DEFAULT_INT + hex + default INT_SOURCE + +config HEX_RANGE_INT + hex + range INT_SOURCE 0x1 + +# Referencing the same type is valid + +config INT_FROM_INT + int + default INT_SOURCE + +config HEX_FROM_HEX + hex + range 0 HEX_SOURCE diff --git a/scripts/kconfig/tests/err_num_mismatch/__init__.py b/scripts/k= config/tests/err_num_mismatch/__init__.py new file mode 100644 index 000000000000..275f2a6e9a5b --- /dev/null +++ b/scripts/kconfig/tests/err_num_mismatch/__init__.py @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +""" +Reject direct references ('default' or 'range') between int and hex option= s. +""" + + +def test(conf): + assert conf.olddefconfig() =3D=3D 1 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/err_num_mismatch/expected_stderr b/scrip= ts/kconfig/tests/err_num_mismatch/expected_stderr new file mode 100644 index 000000000000..587c34467ae6 --- /dev/null +++ b/scripts/kconfig/tests/err_num_mismatch/expected_stderr @@ -0,0 +1,4 @@ +Kconfig:14: error: 'HEX_SOURCE' is an invalid value for 'integer' +Kconfig:18: error: 'HEX_SOURCE' is an invalid value for 'integer' +Kconfig:24: error: 'INT_SOURCE' is an invalid value for 'hex' +Kconfig:28: error: 'INT_SOURCE' is an invalid value for 'hex' --=20 2.55.0 From nobody Fri Sep 25 06:46:57 2026 Received: from mail-wm2-f13.google.com (mail-wm2-f13.google.com [74.125.225.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1A344A4F15 for ; Tue, 15 Sep 2026 21:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506924; cv=none; b=ngtFTEgMTPXyOIgSY3Ynsp0ZRz0LXnHaH5+c8jqUo1ZQDfDNVI4Hpl73jkalMATvxW5oh/o5tloUBthO44STcuTrqWhN+FWcxpTipg0snR0nCj2niRW80rguZrjH6Q8WnmIgPOpEDjaf8tQdnEblImHi+L0tIRf6qShGj7PJ9ww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506924; c=relaxed/simple; bh=Va0vYEznGgN5IvsG3Y+1s+N7u/nKGK2+xOSpnzhu8rg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mx9mxllimQudIjvMtyQQ6k478envW58GqyOA/vWQFRIqpqMGNkmHvmrGRqAALTeVj3j5GUiaTjOW6Q7pGeUZ92JRwP0A2oFVez5zT86du3+J1Yr8QuduHz1VjnizVm4YdjoeWDWYZDZjWMBN/WDx5VPToFlw1DaU6NS8ZEI71wE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fVC0eJW2; arc=none smtp.client-ip=74.125.225.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fVC0eJW2" Received: by mail-wm2-f13.google.com with SMTP id 5b1f17b1804b1-49b912d3931so1808895e9.3 for ; Tue, 15 Sep 2026 14:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789506920; x=1790111720; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to:content-type; bh=i6ZGHNtN6W4sgVfyHGRO9BipB405uodOKVOa/IqqFEc=; b=fVC0eJW2dPvjl6/SBl+iWCkoOQaplUfKkIeE6IKuAvHx/FWlFiihQDXlE34Ri0Xk20 UqbBpTTNemcOnjvGFYTFaKKdQuG9FQPNOasfd1PR7P/a5RAnnPs48efOJCaNqFHdcGvR yFMHDSX9sLWzEmS/XjFDL/pffnf3yHAvTMgic6n/x3QJeE9hJhZ35esTHMp13WIdoPmZ rKiB+csuFwQlXQ6J0UJFWB9+onAh6STSgTzKPlHnhv5LW8pVcIANX456z7KWr9Yb30nC mYtUvoo/zwKzPuDmqgISl5HBml/PbTduYdcphxNudHfMlvXGzl0L4dRbZ9J7XJk0pL3y tPfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789506920; x=1790111720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=i6ZGHNtN6W4sgVfyHGRO9BipB405uodOKVOa/IqqFEc=; b=cadKlz5BWN4Bjk8JKfH9Z5AB5wa5NzyIY8duRzYvmFWSrhmRLjZsA3K6IT3puQ7u0S IILOuJzrVTo1frnc7Ota28nQPb7EmgfCq6CP8Eicak0FOliRZhEYyZw5Ns4NCJDkGwLG mxVSD6J0hrJl4EgSryoUzF3PTkdsDvhtGCLLIg8ZULwjnEBUGkT3OEuNxwxvcsTbRY8w SrihpLmd0Tdl5+ms0oZOE1112l5ogXZPTKPBboVQxv6RuUDePAzXKO7qoQB1dbFN5Hys uUlf5XB48GndiHCn9KIqUQFckHN4FAUxknLZGkAZxFlNYWTZ6TlwiYG07WGjELCKy3OJ qTMw== X-Forwarded-Encrypted: i=1; AKwUvByM1TXvh9BT7Ilf0hryzM1wBA0IdZzAhLks3tB7ybCL03+YA0dIsK2M/KGump7lNaMQ3izXsjw7Ev8sSRI=@vger.kernel.org X-Gm-Message-State: AFuF++m37Zn0xAq9PvQne/prrKtxZdZR7QCzNV5+YvQLwy7KLFW7uZgv tUfMoY9UWzjrebWOtzxYsJ0sinfKIEvz+q+fVNXLEfiuk7IqM6GD6QHP X-Gm-Gg: AYBFou2hEpBXcCWo2h5Lg9Cbe0pW6xOgdyXY/ayikrCCabklb06RR2FbwMD76Yh+IQ+ Wp4B3+k1ul4UM7cQJlX8/bCzKHRlD9Lrl/dGgDT9kmX291FFurkiwMk7CZhU830NMMEhd7zQYOr m9yqaXM9PzLoGh1YhXATNXf61cl2Rww/Kx/2lk+jvZWWePyajrXvQRPdUDoMXs5QQZN3dNw2H5T Ls9elsYiLJ6sIkIlO60pXsSTJJZUSDLNMoQI5jv1a7VMtU4SWU6uZZ+iMFtIC7wSKHrTkBQwhfn 5t3sP/tQMayFGBmo3ODqb/NBrdl8+h30pXAMacdvdWRSlEPq7nfQbf+C/WfgbudpXZ7v2ckBRng 0oFpeTKGys5C1h4EuMdEk03KXySdA+myifMkrWp7FT4GoHFxs1aOOtAqJd859zRnH7MVh0epGt8 f1eXdXVQxSknZfEIj/yNfwboeqzzW9BX0ahdMnI0nW+nepuu6irSKTf9weS6wxvT8e++weBM79Q VTsBJfLsZE0O1xvotd1OPBjCzNUONYVw8BG X-Received: by 2002:a05:600c:35c2:b0:49c:eb16:9fd with SMTP id 5b1f17b1804b1-49e821ffef1mr44587315e9.3.1789506919880; Tue, 15 Sep 2026 14:15:19 -0700 (PDT) Received: from nixos-office ([2001:8a0:e962:d100:b3c:e4b2:2d5f:e949]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e83b1ba9bsm24804695e9.15.2026.09.15.14.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 14:15:19 -0700 (PDT) Sender: Julian Braha From: Julian Braha To: nathan@kernel.org, nsc@kernel.org Cc: nico@fluxnic.net, rdunlap@infradead.org, grahamr@qti.qualcomm.com, kees@kernel.org, pengpeng@iscas.ac.cn, vegard.nossum@oracle.com, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Julian Braha Subject: [PATCH v2 4/5] kconfig: prevent out-of-bounds user input for numeric options Date: Tue, 15 Sep 2026 22:15:07 +0100 Message-ID: <20260915211508.291790-5-julianbraha@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260915211508.291790-1-julianbraha@gmail.com> References: <20260915211508.291790-1-julianbraha@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, user input of out-of-bounds values for 'int' and 'hex' options is possible, leading to later silent failures in Kconfig if that value is used in a comparison, or a warning by GCC or error by Clang if used in the C code. Let's factor out the out-of-bounds check on constants, so that it can be reused for checking user input. The frontend will now reject an attempted user input of an out-of-bounds numeric value, similarly to how a value outside the active 'range' already does. For migration of existing configurations, a .config file with an out-of-bounds numeric value will be allowed for now, but will warn the user when read in by confdata.c Assisted-by: LLM Signed-off-by: Julian Braha Reviewed-by: Nicolas Schier --- scripts/kconfig/confdata.c | 6 +++++ scripts/kconfig/lkc_proto.h | 1 + scripts/kconfig/menu.c | 19 +++----------- scripts/kconfig/symbol.c | 20 +++++++++++++++ .../tests/err_num_bounds/expected_stderr | 20 +++++++-------- scripts/kconfig/tests/warn_num_bounds/Kconfig | 24 ++++++++++++++++++ .../kconfig/tests/warn_num_bounds/__init__.py | 25 +++++++++++++++++++ scripts/kconfig/tests/warn_num_bounds/config | 7 ++++++ .../tests/warn_num_bounds/expected_config | 11 ++++++++ .../warn_num_bounds/expected_config_stderr | 3 +++ .../warn_num_bounds/expected_frontend_config | 11 ++++++++ .../warn_num_bounds/expected_frontend_stderr | 0 12 files changed, 121 insertions(+), 26 deletions(-) create mode 100644 scripts/kconfig/tests/warn_num_bounds/Kconfig create mode 100644 scripts/kconfig/tests/warn_num_bounds/__init__.py create mode 100644 scripts/kconfig/tests/warn_num_bounds/config create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_config create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_config_s= tderr create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_frontend= _config create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_frontend= _stderr diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 4234a51d16fd..2227d89d6328 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -354,6 +354,12 @@ static int conf_set_sym_val(struct symbol *sym, int de= f, int def_flags, char *p) case S_INT: case S_HEX: if (sym_string_valid(sym, p)) { + if (def !=3D S_DEF_AUTO && + !sym_string_check_bounds(sym, p)) + /* hex uses 64-bit unsigned integer */ + conf_warning("value '%s' for %s is outside the 64-bit %s integer bound= s", + p, sym->name, + sym->type =3D=3D S_INT ? "signed" : "unsigned"); sym->def[def].val =3D xstrdup(p); sym->flags |=3D def_flags; } else { diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 8914b4e8f2a8..8b436c87ba4a 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -31,6 +31,7 @@ bool sym_set_tristate_value(struct symbol *sym,tristate t= ri); void choice_set_value(struct menu *choice, struct symbol *sym); tristate sym_toggle_tristate_value(struct symbol *sym); bool sym_string_valid(struct symbol *sym, const char *newval); +bool sym_string_check_bounds(struct symbol *sym, const char *str); bool sym_string_within_range(struct symbol *sym, const char *str); bool sym_set_string_value(struct symbol *sym, const char *newval); bool sym_is_changeable(const struct symbol *sym); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 2d8b0c65ce1e..6b9ef738ee71 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -4,7 +4,6 @@ */ =20 #include -#include #include #include #include @@ -239,8 +238,6 @@ void menu_add_symbol(enum prop_type type, struct symbol= *sym, struct expr *dep) static int menu_validate_number(struct symbol *sym, struct symbol *sym2, const struct property *prop) { - const char *type_bounds; - if (sym->type !=3D S_INT && sym->type !=3D S_HEX) return 0; =20 @@ -255,21 +252,11 @@ static int menu_validate_number(struct symbol *sym, s= truct symbol *sym2, return 1; } =20 - errno =3D 0; - if (sym->type =3D=3D S_INT) { - type_bounds =3D "64-bit signed integer"; - strtoll(sym2->name, NULL, 10); - } else { - /* hex */ - type_bounds =3D "64-bit unsigned integer"; - strtoull(sym2->name, NULL, 16); - } - - if (errno =3D=3D ERANGE) { + if (!sym_string_check_bounds(sym, sym2->name)) { fprintf(stderr, - "%s:%d: error: %s constant '%s' is outside the %s bounds\n", + "%s:%d: error: %s constant '%s' is outside the 64-bit %s bounds\n", prop->filename, prop->lineno, sym_type_name(sym->type), - sym2->name, type_bounds); + sym2->name, sym->type =3D=3D S_INT ? "signed" : "unsigned"); =20 return 1; } diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index e82f330fb8ee..0b3d19af269f 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -5,6 +5,7 @@ =20 #include #include +#include #include #include #include @@ -711,6 +712,21 @@ bool sym_string_valid(struct symbol *sym, const char *= str) } } =20 +bool sym_string_check_bounds(struct symbol *sym, const char *str) +{ + errno =3D 0; + + if (sym->type =3D=3D S_INT) + strtoll(str, NULL, 10); + else if (sym->type =3D=3D S_HEX) + strtoull(str, NULL, 16); + else + /* string */ + return true; + + return errno !=3D ERANGE; +} + bool sym_string_within_range(struct symbol *sym, const char *str) { struct property *prop; @@ -722,6 +738,8 @@ bool sym_string_within_range(struct symbol *sym, const = char *str) case S_INT: if (!sym_string_valid(sym, str)) return false; + if (!sym_string_check_bounds(sym, str)) + return false; prop =3D sym_get_range_prop(sym); if (!prop) return true; @@ -731,6 +749,8 @@ bool sym_string_within_range(struct symbol *sym, const = char *str) case S_HEX: if (!sym_string_valid(sym, str)) return false; + if (!sym_string_check_bounds(sym, str)) + return false; prop =3D sym_get_range_prop(sym); if (!prop) return true; diff --git a/scripts/kconfig/tests/err_num_bounds/expected_stderr b/scripts= /kconfig/tests/err_num_bounds/expected_stderr index 3f06e13359ef..5f89cf4afff8 100644 --- a/scripts/kconfig/tests/err_num_bounds/expected_stderr +++ b/scripts/kconfig/tests/err_num_bounds/expected_stderr @@ -1,10 +1,10 @@ -Kconfig:51: error: integer constant '10000000000000000000' is outside the = 64-bit signed integer bounds -Kconfig:55: error: integer constant '-9223372036854775809' is outside the = 64-bit signed integer bounds -Kconfig:59: error: integer constant '10000000000000000000' is outside the = 64-bit signed integer bounds -Kconfig:63: error: integer constant '-10000000000000000000' is outside the= 64-bit signed integer bounds -Kconfig:67: error: integer constant '-9223372036854775809' is outside the = 64-bit signed integer bounds -Kconfig:67: error: integer constant '10000000000000000000' is outside the = 64-bit signed integer bounds -Kconfig:71: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned integer bounds -Kconfig:75: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned integer bounds -Kconfig:79: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned integer bounds -Kconfig:79: error: hex constant '0x20000000000000000' is outside the 64-bi= t unsigned integer bounds +Kconfig:51: error: integer constant '10000000000000000000' is outside the = 64-bit signed bounds +Kconfig:55: error: integer constant '-9223372036854775809' is outside the = 64-bit signed bounds +Kconfig:59: error: integer constant '10000000000000000000' is outside the = 64-bit signed bounds +Kconfig:63: error: integer constant '-10000000000000000000' is outside the= 64-bit signed bounds +Kconfig:67: error: integer constant '-9223372036854775809' is outside the = 64-bit signed bounds +Kconfig:67: error: integer constant '10000000000000000000' is outside the = 64-bit signed bounds +Kconfig:71: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned bounds +Kconfig:75: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned bounds +Kconfig:79: error: hex constant '0x10000000000000000' is outside the 64-bi= t unsigned bounds +Kconfig:79: error: hex constant '0x20000000000000000' is outside the 64-bi= t unsigned bounds diff --git a/scripts/kconfig/tests/warn_num_bounds/Kconfig b/scripts/kconfi= g/tests/warn_num_bounds/Kconfig new file mode 100644 index 000000000000..a810225a58a3 --- /dev/null +++ b/scripts/kconfig/tests/warn_num_bounds/Kconfig @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0 + +mainmenu "Numeric bounds test" + +config INT_TOO_LOW + int "Integer below its type bounds" + +config INT_TOO_HIGH + int "Integer above its type bounds" + +config HEX_TOO_HIGH + hex "Hex value above its type bounds" + +config INT_MIN + int "Minimum valid integer" + +config INT_MAX + int "Maximum valid integer" + +config HEX_MIN + hex "Minimum valid hex value" + +config HEX_MAX + hex "Maximum valid hex value" diff --git a/scripts/kconfig/tests/warn_num_bounds/__init__.py b/scripts/kc= onfig/tests/warn_num_bounds/__init__.py new file mode 100644 index 000000000000..db7518258217 --- /dev/null +++ b/scripts/kconfig/tests/warn_num_bounds/__init__.py @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-2.0 +"""Test user values outside the numeric type bounds.""" + + +def test(conf): + in_keys =3D ( + '-9223372036854775809\n' + '-1\n' + '9223372036854775808\n' + '1\n' + '0x10000000000000000\n' + '0x1\n' + '-9223372036854775808\n' + '9223372036854775807\n' + '0x0\n' + '0xffffffffffffffff\n' + ) + + assert conf.oldaskconfig(in_keys=3Din_keys) =3D=3D 0 + assert conf.stderr_matches('expected_frontend_stderr') + assert conf.config_matches('expected_frontend_config') + + assert conf.olddefconfig('config') =3D=3D 0 + assert conf.stderr_matches('expected_config_stderr') + assert conf.config_matches('expected_config') diff --git a/scripts/kconfig/tests/warn_num_bounds/config b/scripts/kconfig= /tests/warn_num_bounds/config new file mode 100644 index 000000000000..74bf263f99bf --- /dev/null +++ b/scripts/kconfig/tests/warn_num_bounds/config @@ -0,0 +1,7 @@ +CONFIG_INT_TOO_LOW=3D-9223372036854775809 +CONFIG_INT_TOO_HIGH=3D9223372036854775808 +CONFIG_HEX_TOO_HIGH=3D0x10000000000000000 +CONFIG_INT_MIN=3D-9223372036854775808 +CONFIG_INT_MAX=3D9223372036854775807 +CONFIG_HEX_MIN=3D0x0 +CONFIG_HEX_MAX=3D0xffffffffffffffff diff --git a/scripts/kconfig/tests/warn_num_bounds/expected_config b/script= s/kconfig/tests/warn_num_bounds/expected_config new file mode 100644 index 000000000000..8b1aef612bc6 --- /dev/null +++ b/scripts/kconfig/tests/warn_num_bounds/expected_config @@ -0,0 +1,11 @@ +# +# Automatically generated file; DO NOT EDIT. +# Numeric bounds test +# +CONFIG_INT_TOO_LOW=3D-9223372036854775809 +CONFIG_INT_TOO_HIGH=3D9223372036854775808 +CONFIG_HEX_TOO_HIGH=3D0x10000000000000000 +CONFIG_INT_MIN=3D-9223372036854775808 +CONFIG_INT_MAX=3D9223372036854775807 +CONFIG_HEX_MIN=3D0x0 +CONFIG_HEX_MAX=3D0xffffffffffffffff diff --git a/scripts/kconfig/tests/warn_num_bounds/expected_config_stderr b= /scripts/kconfig/tests/warn_num_bounds/expected_config_stderr new file mode 100644 index 000000000000..be2ed7fbf648 --- /dev/null +++ b/scripts/kconfig/tests/warn_num_bounds/expected_config_stderr @@ -0,0 +1,3 @@ +.config:1:warning: value '-9223372036854775809' for INT_TOO_LOW is outside= the 64-bit signed integer bounds +.config:2:warning: value '9223372036854775808' for INT_TOO_HIGH is outside= the 64-bit signed integer bounds +.config:3:warning: value '0x10000000000000000' for HEX_TOO_HIGH is outside= the 64-bit unsigned integer bounds diff --git a/scripts/kconfig/tests/warn_num_bounds/expected_frontend_config= b/scripts/kconfig/tests/warn_num_bounds/expected_frontend_config new file mode 100644 index 000000000000..a7e842517026 --- /dev/null +++ b/scripts/kconfig/tests/warn_num_bounds/expected_frontend_config @@ -0,0 +1,11 @@ +# +# Automatically generated file; DO NOT EDIT. +# Numeric bounds test +# +CONFIG_INT_TOO_LOW=3D-1 +CONFIG_INT_TOO_HIGH=3D1 +CONFIG_HEX_TOO_HIGH=3D0x1 +CONFIG_INT_MIN=3D-9223372036854775808 +CONFIG_INT_MAX=3D9223372036854775807 +CONFIG_HEX_MIN=3D0x0 +CONFIG_HEX_MAX=3D0xffffffffffffffff diff --git a/scripts/kconfig/tests/warn_num_bounds/expected_frontend_stderr= b/scripts/kconfig/tests/warn_num_bounds/expected_frontend_stderr new file mode 100644 index 000000000000..e69de29bb2d1 --=20 2.55.0 From nobody Fri Sep 25 06:46:57 2026 Received: from mail-wm2-f12.google.com (mail-wm2-f12.google.com [74.125.225.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E88A4A4419 for ; Tue, 15 Sep 2026 21:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506927; cv=none; b=kvoWqWpa8+8kGcLfPLaDjKmZgyC3L6F9kWtWc91MIlF5zyPLk+ka4oRTD5MBKY/IbeP3GPz18RBxrw83GWMIBAGwfIDqnp3wA2LDeBjc9trxlGMIOF8ZjFT5TJN7i2/xBLkVdJX+CK9hDYabR8TTWBFeeZxDe24Om9wDq/PiexI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789506927; c=relaxed/simple; bh=yJr6rXzrWgdSiYWalW3xVY4HPBFxC9aoiQ7hQDmwGGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FaxUF8/L1mnmjZfiFQ1YJd2z+0wOhkN1vjPP6+uIJQaQN0AsFEGk2FlYghRnzQZPnsnD6lK4Izv4f4hDQEi/66gn4Aong7AuH5WBsvM9Jha7gHGqWqufWiagWqurqUOjFAP72BmgaXYl+M1cwQ5+MTPLs1CdZZVTR+EW7OsdRdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fThmJ3XR; arc=none smtp.client-ip=74.125.225.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fThmJ3XR" Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49b912e4ad9so1390225e9.2 for ; Tue, 15 Sep 2026 14:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789506922; x=1790111722; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8SM88gO19ll3/p4P6X9MOc91tQeF0muhXwwBAXrS5wc=; b=fThmJ3XRQgm8DaSOEBKTLm9yH0r5DDg5vFCge2EBTQqoHoXrKQruVs/WPGEvVbNLgh 86QpmEK58nbnxn2kQCrKj6KTTCADUBcHFlYJ9uC2N8GnS/CoCEv6pSt1qLk4LhGLXOBL sDN9pBWb9aS0lg9AmyLAFbzl23oa9j333fj2xQjlivqOjEw8TChnrQ9GdT5G4Xr0n6PG LqTVoLPjSrg9Jvj5lcuXzFyJegzfntUO2lN1n9NjUQ/wLttvlQ83r8sIKR2Fc8pEsAvs Ye/rQGf06NEY5Nj7PqMZACthSpwwdqqHNyh/V31+DRe8APINVxOzpJyFr1WfTivywsiK O1cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789506922; x=1790111722; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8SM88gO19ll3/p4P6X9MOc91tQeF0muhXwwBAXrS5wc=; b=bzEp6THfmFC5D54x3Di28+qVv9TaW5bo9znj+++iEj6uF6QE9dn2EMxPc+l1ekMoET jNU8hNbBg9Y6rT2O/sEWV7h8qFpD7GEamQXy6SA5vhnzkP7OF6aFoA5ZOBfR5H4WZVch Tujx8PqR5/faUgfhfQmegJ1DSfpmOT7TXl4+5RYThE00sH3bz+jkTkmcPU4DK/vzYVyj P6QbHwjQgcUtU1bXgz8A0jxQGSLnk4X37wyIA/ILAb2dmHhr/yWg9aBSpW+UJBUlK66E Q2KFtC0snGS9K/Ee0+Uj1j7uV/chjuok9PSDfm7UmwUWlQsLt7jJhsuv4OJ54NSGXA9+ i1hw== X-Forwarded-Encrypted: i=1; AKwUvBzJg34XFmog4bGa3defe3nCGGzgHqu0w88TFmql6MQHUL9IpQl3P8oeo/k0UreR6QmDTW1pqcGw/oVbtBU=@vger.kernel.org X-Gm-Message-State: AFuF++nWEa+ZIochKPa8ebTcG/MHPsKtBrzPm5rACTokojRu7MSxXybu ExlrkbAO5xJxRKwPCREZ8u8QzLXnUv2dNBGYE81Aw21IoOysbN1OR2ym X-Gm-Gg: AYBFou1X22MAGgSFVRc6AR4yNW/r8LyXy3RWGEMVPJLi+1WG4CjVxxBaavo+yhLibis 1lQNyr0opoSKSi5JjQwJhGT7OQFWXoOO2sMA2X/YCJBJ8q5Y37xkhzsPMPZyFC0rmKiK2j9XUTr /U/F2G+RAM+n+ZwiN2hHDoh8XGpCKwFRnrpKnHbt14np+L8E8wrphJsYeed7CVlkhEyHInH0fkN HgOOB1dtv65cGBoybdOzi0m2pTXfIZvzUJYjQOxlVuRHKhrgycxCGaRPaPJjhSdevN8b0xuE4JW jaDz++6N879HrHN8SGU+KC9J266tEqrhjDQ44EXe5Y+1AAzb8uUEUSVVqP8+eS1tlPhMjxjmTrd XbmL6i/H/zRKTKaIB1ez59PnxYZEX1qMvevgf+4TdKEIz7SxtQjGcUy9XJwGDylO0a7fmB8xTxd yo8MwtEl0AwL9K/boosAzEm25nclpRXmF93FihVMahGlVs9yBY/eQ+QSlIzQyNnzu4hFDhkRbEO +H7qS6Mqt5BBg6deXVH4dqlWXHmBYvOa7QI X-Received: by 2002:a05:600c:6298:b0:49e:660a:935e with SMTP id 5b1f17b1804b1-49e822b5626mr32541615e9.29.1789506922003; Tue, 15 Sep 2026 14:15:22 -0700 (PDT) Received: from nixos-office ([2001:8a0:e962:d100:b3c:e4b2:2d5f:e949]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e83b1ba9bsm24804695e9.15.2026.09.15.14.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 14:15:21 -0700 (PDT) Sender: Julian Braha From: Julian Braha To: nathan@kernel.org, nsc@kernel.org Cc: nico@fluxnic.net, rdunlap@infradead.org, grahamr@qti.qualcomm.com, kees@kernel.org, pengpeng@iscas.ac.cn, vegard.nossum@oracle.com, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Julian Braha Subject: [PATCH v2 5/5] kconfig: use unsigned integers for hex range checks Date: Tue, 15 Sep 2026 22:15:08 +0100 Message-ID: <20260915211508.291790-6-julianbraha@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260915211508.291790-1-julianbraha@gmail.com> References: <20260915211508.291790-1-julianbraha@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" While 'hex' values should use the bounds of 64-bit unsigned integers, the range values are treated as signed (checks use strtoll). For example: config HEX_RANGE hex range 0 0xfffffffffffffffe default 0xffffffffffffffff the default value should adjust down to the upper bound of 0xfffffffffffffffe, but since the check incorrectly parses both as LLONG_MAX, the value stays at the out-of-range default of 0xffffffffffffffff. To fix this, let's use a union of signed and unsigned integers to represent both 'int' and 'hex' range values, then use both strtoll and strtoull where appropriate. Assisted-by: LLM Signed-off-by: Julian Braha Reviewed-by: Nicolas Schier --- scripts/kconfig/symbol.c | 41 ++++++++++++++----- .../kconfig/tests/warn_changed_input/Kconfig | 5 +++ .../tests/warn_changed_input/expected_config | 1 + 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 0b3d19af269f..14b029f9d6df 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -142,8 +142,15 @@ struct property *sym_get_range_prop(struct symbol *sym) return NULL; } =20 -static long long sym_get_range_val(struct symbol *sym, int base) +union range_value { + long long s; + unsigned long long u; +}; + +static union range_value sym_get_range_val(struct symbol *sym, int base) { + union range_value val; + sym_calc_value(sym); switch (sym->type) { case S_INT: @@ -155,7 +162,12 @@ static long long sym_get_range_val(struct symbol *sym,= int base) default: break; } - return strtoll(sym->curr.val, NULL, base); + if (base =3D=3D 10) + val.s =3D strtoll(sym->curr.val, NULL, base); + else + /* HEX */ + val.u =3D strtoull(sym->curr.val, NULL, base); + return val; } =20 static void sym_validate_range(struct symbol *sym) @@ -163,7 +175,7 @@ static void sym_validate_range(struct symbol *sym) struct property *prop; struct symbol *range_sym; int base; - long long val, val2; + union range_value val, val2; =20 switch (sym->type) { case S_INT: @@ -178,13 +190,19 @@ static void sym_validate_range(struct symbol *sym) prop =3D sym_get_range_prop(sym); if (!prop) return; - val =3D strtoll(sym->curr.val, NULL, base); + val =3D sym_get_range_val(sym, base); range_sym =3D prop->expr->left.sym; val2 =3D sym_get_range_val(range_sym, base); - if (val >=3D val2) { + + if (base =3D=3D 10 && val.s >=3D val2.s) { + range_sym =3D prop->expr->right.sym; + val2 =3D sym_get_range_val(range_sym, base); + if (val.s <=3D val2.s) + return; + } else if (base =3D=3D 16 && val.u >=3D val2.u) { range_sym =3D prop->expr->right.sym; val2 =3D sym_get_range_val(range_sym, base); - if (val <=3D val2) + if (val.u <=3D val2.u) return; } sym->curr.val =3D range_sym->curr.val; @@ -731,6 +749,7 @@ bool sym_string_within_range(struct symbol *sym, const = char *str) { struct property *prop; long long val; + unsigned long long uval; =20 switch (sym->type) { case S_STRING: @@ -744,8 +763,8 @@ bool sym_string_within_range(struct symbol *sym, const = char *str) if (!prop) return true; val =3D strtoll(str, NULL, 10); - return val >=3D sym_get_range_val(prop->expr->left.sym, 10) && - val <=3D sym_get_range_val(prop->expr->right.sym, 10); + return val >=3D sym_get_range_val(prop->expr->left.sym, 10).s && + val <=3D sym_get_range_val(prop->expr->right.sym, 10).s; case S_HEX: if (!sym_string_valid(sym, str)) return false; @@ -754,9 +773,9 @@ bool sym_string_within_range(struct symbol *sym, const = char *str) prop =3D sym_get_range_prop(sym); if (!prop) return true; - val =3D strtoll(str, NULL, 16); - return val >=3D sym_get_range_val(prop->expr->left.sym, 16) && - val <=3D sym_get_range_val(prop->expr->right.sym, 16); + uval =3D strtoull(str, NULL, 16); + return uval >=3D sym_get_range_val(prop->expr->left.sym, 16).u && + uval <=3D sym_get_range_val(prop->expr->right.sym, 16).u; case S_BOOLEAN: case S_TRISTATE: switch (str[0]) { diff --git a/scripts/kconfig/tests/warn_changed_input/Kconfig b/scripts/kco= nfig/tests/warn_changed_input/Kconfig index 69845e2f3fb3..df4183a08420 100644 --- a/scripts/kconfig/tests/warn_changed_input/Kconfig +++ b/scripts/kconfig/tests/warn_changed_input/Kconfig @@ -26,6 +26,11 @@ config NUM Kconfig resolves it to the constrained in-range value. The warning should report that adjustment. =20 +config HEX_RANGE + hex + range 0 0xfffffffffffffffe + default 0xffffffffffffffff + config DUP bool "DUP" depends on DEP diff --git a/scripts/kconfig/tests/warn_changed_input/expected_config b/scr= ipts/kconfig/tests/warn_changed_input/expected_config index fe8bbec66c53..6a8d98a69b7e 100644 --- a/scripts/kconfig/tests/warn_changed_input/expected_config +++ b/scripts/kconfig/tests/warn_changed_input/expected_config @@ -4,3 +4,4 @@ # # CONFIG_DEP is not set CONFIG_NUM=3D20 +CONFIG_HEX_RANGE=3D0xfffffffffffffffe --=20 2.55.0