From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 9798826F2BE for ; Mon, 27 Apr 2026 22:04:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777327491; cv=none; b=SDmObj0fGyxJjg71Mshn1nazTUAeikM4+GwV6x7jrF0jqTM4QFs8YExWmDwKa0aM7GbA1Sm9niTsD/WzNTJBCViZ4Uoi5SG0jQiApCONgi9ORx3f8CbI6XuTTDlwZ67ZvW8xVLTlXEhYOCSRbwNTPd+tAXu2W6OI7Nx8YrbFY7w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777327491; c=relaxed/simple; bh=Ta8iQJRfpSSO8QGXXxAKfWyt5kKIrJMmYHF6M5pdPPA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=JMqMR0f45V7XYPvj0LDeVrjlTymK2eqL3KGC3nEayYL2medSzELj195T8SR2tAddGLV3+fmLIDKwPM5vax1Yhz84NymDXR7dpopZANZ1BFxHpTOZv64JoYgra3KHBlxBWpc3Xyj88xf15y4S1OQXsrf8rf7m+NouNdAN2+gA2Y0= 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=GjK24HDg; arc=none smtp.client-ip=209.85.221.50 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="GjK24HDg" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-43d734223e4so7257769f8f.0 for ; Mon, 27 Apr 2026 15:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777327489; x=1777932289; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3giwzTv4Lg8DVmhadG5YJN5KYq+BKuDUQT/RmH+W7e4=; b=GjK24HDgfX4q5IXBQd7jgo165SwfQVCF74qKafBr/KWdoFDnhnwcjIKsQ8GTEbQ6sR 9Rbyewmngsd4JMO83PodcbHJJsO0eS/38NADb9IiwkNzrxOCQZMsafybzGKPcxn8NXS7 ELqTqCRnle9nPLZe0dVNhKDOBoC76tDhi+at615MLinjSWtoZsFZ2aYGb6TCTlkUEnFI yqekeNt1nDYbA6Mk+/Oi2MD5zR+xkIEIHb4tvKigwKL99zbRl+W8Q45B+lbgQGn/R6o6 fyct3IKEkjdiCL5AWv3jQ8n5VG1Qv7dR7WcF4w2ARjCY/xHxZu/N/QHuvgAIsNn6SdmT VvKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777327489; x=1777932289; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3giwzTv4Lg8DVmhadG5YJN5KYq+BKuDUQT/RmH+W7e4=; b=ou/I2tsDXVcu7eW0dAXE89WRyzDoGK3GN1zcXos9pc02DJ1YNlcihNT92ZEJdPe72j BYLhIMVxrxoZqb2KOGXjpy3ERpdcJgCwrwW85PJ0eQ6MKNMZJ4iVFEdgF8HBY0KiWfxm eCwy4Fq90aJJR4EPFhuW1SnlaqvDDTLnPNtiwQs0yWDccmreHSsrGMYHffFNNn3wRaAx YMKH0mQQLr85w/oZF+qR6KmiQNg+IOOhuOwq6BxP/DFTVJglunCkzbAOQJC0kyCd0bYe 3YQ5EC++KLqTzhiK51IY7QjoPSlWHJvW26GQfJ0iXuMPusgxO0n2ziWbUd0HYOq/AXuu 75QA== X-Gm-Message-State: AOJu0Yx90qyGGws9OutWHaIa1iI8R3yu2kFlrVoTRpfy2Wc+acvFyO8v oFhz8Gl2qMu6DSr+OWfOQJvcTbp5a3db9kVKw2npW5eixxXv/QkEPfVTTv36jGMb X-Gm-Gg: AeBDietosp3B4wv1xaYYQg2VybXFgJOdT4jqKqj8dX8mJ/Isdaf3pte/UI15cl7abCU /syUXsBvj2URi+uB+kuCoqT2v0pxFu4RasZXKP8Uolxbu0axRZj86EtEOff7oTiIp96AxJqX05W vNjiFfzhMpPoefgaDhiWMlov57mVb6l0gxLNnwYY7hiWOd+cydcy+mTzcNlPJmfDeBRpx5Bwb4o KXLi9UVha3zFp81Nt8hUJvBiRf5pn5vM15UAnrcNqKjnjlUHelzJmCwI59DME0RCXZ1wJ03/sw3 psCDkIhbVv+gxFH8w8GOgH0wN4lzGfAUxaf/86ze4AmjnKm5wJR6l2FxijBlH6atj9znh3FnI2m tjr//LmdDrlKze39Cp2v6j3okyVnLBR8YxC+f6srZJyAkGcKnXrUZLofnlSZYE2uJEjbsyg+JdS 0BmBQN9RdjUk0TIB3vFStnxxFvozEAPoQGWLhmUxG/JJm2cVPQHOldYeijuInbb6qARDz1aXOLe nFM70eueKQ8n+JGv6p5rg== X-Received: by 2002:a05:6000:20c8:b0:43f:df55:fe5e with SMTP id ffacd0b85a97d-4464c7cf2e7mr482540f8f.0.1777327488406; Mon, 27 Apr 2026 15:04:48 -0700 (PDT) Received: from localhost.localdomain (200.178.141.77.rev.sfr.net. [77.141.178.200]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4463fa89038sm1287014f8f.26.2026.04.27.15.04.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 27 Apr 2026 15:04:47 -0700 (PDT) From: Hasan Basbunar To: linux-kernel@vger.kernel.org Cc: Steven Rostedt , Hasan Basbunar Subject: [PATCH] scripts/sorttable: fix off-by-one in do_sort() symbol-table walk Date: Tue, 28 Apr 2026 00:03:29 +0200 Message-ID: <20260427220329.29327-1-basbunarhasan@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The for-loop in do_sort() that searches .symtab for the main_extable_sort_needed flag uses a strict less-than predicate that includes the symentsize: for (sym = sym_start; (void *)sym + symentsize < sym_end; sym = (void *)sym + symentsize) { For a .symtab of N entries each symentsize bytes, sym_end - sym_start == N * symentsize. After k advances sym is at offset k * symentsize, so the predicate (void *)sym + symentsize < sym_end reduces to (k+1) * symentsize < N * symentsize, i.e. k < N-1. The body therefore runs for k = 0..N-2 only — N-1 iterations — and the entry at index N-1 is never visited. If main_extable_sort_needed happens to occupy the very last slot of .symtab, the search silently fails, sort_needed_sym stays NULL, and do_sort() prints no main_extable_sort_needed symbol in file: aborting the post-link sort and failing the kernel build for any link order that places that symbol last. The companion loop just above in the same file at scripts/sorttable.c:563 (get_mcount_loc()) walks the same .symtab correctly: while (sym < end_sym) { ... sym = (void *)sym + symentsize; } and includes the final entry. The two loops disagreed on whether the last symbol is part of the table — clearly unintended. Align do_sort()'s walk on the companion loop's predicate so every .symtab entry is examined. sym_end is the one-past-the-end pointer of the .symtab mapping (sym_start + shdr_size(symtab_sec)), so a single (void *)sym < sym_end check is sufficient and matches the get_mcount_loc() pattern verbatim. Reproduced with a stand-alone harness lifting the predicate verbatim: on a 5-entry synthetic .symtab the buggy form visits 4 entries and misses the last; the fixed form visits all 5. Fixes: 200d015e73b4 ("scripts/sorttable: Convert Elf_Sym MACRO over to a union") Signed-off-by: Hasan Basbunar --- scripts/sorttable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sorttable.c b/scripts/sorttable.c index e8ed11c680c6..dd69b1a9f9ec 100644 --- a/scripts/sorttable.c +++ b/scripts/sorttable.c @@ -751,7 +751,7 @@ static int do_sort(Elf_Ehdr *ehdr, sym_end = sym_start + shdr_size(symtab_sec); symentsize = shdr_entsize(symtab_sec); - for (sym = sym_start; (void *)sym + symentsize < sym_end; + for (sym = sym_start; (void *)sym < sym_end; sym = (void *)sym + symentsize) { if (sym_type(sym) != STT_OBJECT) continue; -- 2.53.0