From nobody Fri Dec 19 04:58:43 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 68E0D19A2AE for ; Thu, 27 Jun 2024 23:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719530365; cv=none; b=a4yZh8xxcmbu2Dzhx4ZRLF601gyshkdP2N6UMuNjunYg8Jb/CKpz4nvp90N8ZFrsaKLCv6fEjvAL69SFSukuEsNTdPsEj2JGccbUrpx3GrudmwTl/63Z8fDCJyr7UoqtJplrdB9WaB866D2KQ5BjqW0U+0+kc8FgcDTRS80hc+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719530365; c=relaxed/simple; bh=DrCqKiL/pCMihlN46mvRvR8EclvzSD4pZGIIsWvU/0I=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=fGEerYbUGufkB4HvVaRqhkW2NTd1MTtiewpf/pHPkS6YIGxTcSc58kdq/YgzGQh59Yp7W3zd3qq9XScItuXVkGNqmKlP4WG/pyvoutwZjKpF9UUjR8vNg2UoPlacXq8dcPTPJLWCSb/LziIGHo2UVqFZOeAfSGlg4jPhR8Ww1hA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elsk.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JOoAfhvh; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elsk.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JOoAfhvh" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e0322e5d0daso125910276.0 for ; Thu, 27 Jun 2024 16:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719530361; x=1720135161; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lbeqboMNXPvpri+31lcbyxGvW1jhsLnKPupd3d+M1PU=; b=JOoAfhvhAzH3XsUMbZKccTzpgflGskGhayhrPKY/h5dbGyIj8i8B28XuCJ0HEpeLJe aROHzmluAUF5sJajpdZlPBXTTeqotKQ5+7jsMTgndTw2Bcoj4ALn8bUmCH8IKs+8kVWB GWvJXsspuPe/NIQQFdWKBZBYsk6m0Zvdc2VSxeGPRYb3boRSfgWO5Wjpf9rnQXK7yOUk pWebxjewMvRQ4YEeykJRXySpFjQcPCKUfvZEMwhXz+/G9rHVeBfcLBs6o9E2s50o1OSf o0i6IiH6pi56CsOiB7VAxaJYXblhPKsbAcpuLGgFqmSp0UQF8cz7iS+9Ajz35IbU+pqq sc9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719530361; x=1720135161; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lbeqboMNXPvpri+31lcbyxGvW1jhsLnKPupd3d+M1PU=; b=hAx4TjWvm157X4W4noy6CagfZV5BObItifNUSuAkINL/VoRmD2aeqBGtFwskZYzwwW 6cY5tOQyNJdyuvETztpbxeiYabHE2qe65uEZlrvAQYbimQcM+of1rPHRpBTCGQkfp7w/ 0sGYIobBB+wW0DmQYMmW8lHaeAI54SaZUAF04rgv0wS26LRWsEdrb1thdIEgA1wUMlFd cFqzzIw1GFbgX3SMckZdtFm9XUOPiKJNkN12THnV1q/2/kNFYnba/+o7KlDaXd+qE8+X MrZVbdrYu/TKDlwp6cHe5Qis/B56JY7q3dPkSebgxDUdhRgE6HFwlI2FJE40jlONqMRv IBng== X-Forwarded-Encrypted: i=1; AJvYcCUg2hKF+5sfi/vgqHFL4RfuKZUfXKCWv0D2zXMIk3xjGdpcHbQ/kbvrSHP/weEph2pVnn2VWJTz8F4+/zBri9YusyzMDStnDV26Hjum X-Gm-Message-State: AOJu0Yz9fkPQJ0T/+eMxqY9Keiw8OYVj0VHW7oolZVCIV+8X2GwMBwa3 7MiHLaT3nhPUYgVqOjBj50rDF+Pcx6/gA/wkfAxw+Fkp+02LipfL2p/+WJZJeDIQ14dCWw== X-Google-Smtp-Source: AGHT+IFsOjo+uPSs9HOn7YkmxKzwpRo9G4W7RfOuhhYZWC95tEB560alN/cX4ONJq1ishV2MNcawnZEv X-Received: from elsk.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:dbd]) (user=elsk job=sendgmr) by 2002:a25:51c1:0:b0:e03:5148:9f02 with SMTP id 3f1490d57ef6-e035bff4fe7mr22276.3.1719530361457; Thu, 27 Jun 2024 16:19:21 -0700 (PDT) Date: Thu, 27 Jun 2024 23:19:18 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240627231919.2461945-1-elsk@google.com> Subject: [PATCH v3] kconfig: recursive checks drop file/lineno From: HONG Yifan To: Masahiro Yamada Cc: HONG Yifan , kernel-team@android.com, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This prevents segfault when getting filename and lineno in recursive checks. If the following snippet is found in Kconfig: [Test code 1] config FOO bool depends on BAR select BAR ... without BAR defined; then if one runs `make tinyconfig`, there is a segfault. Kconfig:34:error: recursive dependency detected! Kconfig:34: symbol FOO depends on BAR make[4]: *** [scripts/kconfig/Makefile:85: allnoconfig] Segmentation fault This is because of the following. BAR is a fake entry created by sym_lookup() with prop being NULL. In the recursive check, there is a NULL check for prop to fall back to stack->sym->prop if stack->prop is NULL. However, in this case, stack->sym points to the fake BAR entry created by sym_lookup(), so prop is still NULL. prop was then referenced without additional NULL checks, causing segfault. As the previous email thread suggests, the file and lineno for select is also wrong: [Test code 2] config FOO bool config BAR bool config FOO bool "FOO" depends on BAR select BAR $ make defconfig *** Default configuration is based on 'x86_64_defconfig' Kconfig:1:error: recursive dependency detected! Kconfig:1: symbol FOO depends on BAR Kconfig:4: symbol BAR is selected by FOO [...] Kconfig:4 should be Kconfig:10. This patch deletes the wrong and segfault-prone filename/lineno inference completely. With this patch, Test code 1 yields: error: recursive dependency detected! symbol FOO depends on BAR symbol BAR is selected by FOO Link: https://lore.kernel.org/linux-kbuild/20240620211112.500465-1-elsk@goo= gle.com/ Signed-off-by: HONG Yifan -- v3: Rebase on top of https://lore.kernel.org/linux-kbuild/20240626182212.3758235-1-masahiroy= @kernel.org/T/#t & resolve merge conflicts. Fix scripts/kconfig/tests/err_recursive_dep/expected_stderr v2: Delete all filenames/lineno completely as suggested by masahiroy@kernel.org --- scripts/kconfig/symbol.c | 40 +++++++------------ .../tests/err_recursive_dep/expected_stderr | 36 ++++++++--------- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index c05d188a1857..e22c8769f44f 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1068,10 +1068,10 @@ static void sym_check_print_recursive(struct symbol= *last_sym) { struct dep_stack *stack; struct symbol *sym, *next_sym; - struct menu *menu =3D NULL; struct menu *choice; struct property *prop; struct dep_stack cv_stack; + enum prop_type type; =20 choice =3D sym_get_choice_menu(last_sym); if (choice) { @@ -1094,49 +1094,39 @@ static void sym_check_print_recursive(struct symbol= *last_sym) if (prop =3D=3D NULL) prop =3D stack->sym->prop; =20 - /* for choice values find the menu entry (used below) */ - if (sym_is_choice(sym) || sym_is_choice_value(sym)) { - for (prop =3D sym->prop; prop; prop =3D prop->next) { - menu =3D prop->menu; - if (prop->menu) - break; - } - } + if (prop =3D=3D NULL) + type =3D P_UNKNOWN; + else + type =3D prop->type; + if (stack->sym =3D=3D last_sym) - fprintf(stderr, "%s:%d:error: recursive dependency detected!\n", - prop->filename, prop->lineno); + fprintf(stderr, "error: recursive dependency detected!\n"); =20 if (sym_is_choice(next_sym)) { choice =3D list_first_entry(&next_sym->menus, struct menu, link); =20 - fprintf(stderr, "%s:%d:\tsymbol %s is part of choice block at %s:%d\n", - menu->filename, menu->lineno, + fprintf(stderr, "\tsymbol %s is part of choice block at %s:%d\n", sym->name ? sym->name : "", choice->filename, choice->lineno); } else if (stack->expr =3D=3D &sym->dir_dep.expr) { - fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n", - prop->filename, prop->lineno, + fprintf(stderr, "\tsymbol %s depends on %s\n", sym->name ? sym->name : "", next_sym->name); } else if (stack->expr =3D=3D &sym->rev_dep.expr) { - fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", - prop->filename, prop->lineno, + fprintf(stderr, "\tsymbol %s is selected by %s\n", sym->name, next_sym->name); } else if (stack->expr =3D=3D &sym->implied.expr) { - fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n", - prop->filename, prop->lineno, + fprintf(stderr, "\tsymbol %s is implied by %s\n", sym->name, next_sym->name); } else if (stack->expr) { - fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", - prop->filename, prop->lineno, + fprintf(stderr, "\tsymbol %s %s value contains %s\n", sym->name ? sym->name : "", - prop_get_type_name(prop->type), + prop_get_type_name(type), next_sym->name); } else { - fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n", - prop->filename, prop->lineno, + fprintf(stderr, "\tsymbol %s %s is visible depending on %s\n", sym->name ? sym->name : "", - prop_get_type_name(prop->type), + prop_get_type_name(type), next_sym->name); } } diff --git a/scripts/kconfig/tests/err_recursive_dep/expected_stderr b/scri= pts/kconfig/tests/err_recursive_dep/expected_stderr index 05d4ced70320..fc2e860af082 100644 --- a/scripts/kconfig/tests/err_recursive_dep/expected_stderr +++ b/scripts/kconfig/tests/err_recursive_dep/expected_stderr @@ -1,38 +1,38 @@ -Kconfig:5:error: recursive dependency detected! -Kconfig:5: symbol A depends on A +error: recursive dependency detected! + symbol A depends on A For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" =20 -Kconfig:11:error: recursive dependency detected! -Kconfig:11: symbol B is selected by B +error: recursive dependency detected! + symbol B is selected by B For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" =20 -Kconfig:17:error: recursive dependency detected! -Kconfig:17: symbol C1 depends on C2 -Kconfig:21: symbol C2 depends on C1 +error: recursive dependency detected! + symbol C1 depends on C2 + symbol C2 depends on C1 For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" =20 -Kconfig:27:error: recursive dependency detected! -Kconfig:27: symbol D1 depends on D2 -Kconfig:32: symbol D2 is selected by D1 +error: recursive dependency detected! + symbol D1 depends on D2 + symbol D2 is selected by D1 For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" =20 -Kconfig:37:error: recursive dependency detected! -Kconfig:37: symbol E1 depends on E2 -Kconfig:42: symbol E2 is implied by E1 +error: recursive dependency detected! + symbol E1 depends on E2 + symbol E2 is implied by E1 For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" =20 -Kconfig:49:error: recursive dependency detected! -Kconfig:49: symbol F1 default value contains F2 -Kconfig:51: symbol F2 depends on F1 +error: recursive dependency detected! + symbol F1 default value contains F2 + symbol F2 depends on F1 For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" =20 -Kconfig:60:error: recursive dependency detected! -Kconfig:60: symbol G depends on G +error: recursive dependency detected! + symbol G depends on G For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" --=20 2.45.2.803.g4e1b14247a-goog