From nobody Tue Dec 16 12:37:05 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C3D7264609; Fri, 9 May 2025 20:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746821873; cv=none; b=RO2zU1ogITCghOf7iqYUYk7nsNcbUOrx6gDjmmRAuriimeCuI8Xxof+6w4gMmegNAp9b17k35fZxlnHQEgQ9BFjMsbky07z9IKR8/s6u48dHW4E5ED9eOFAluCGPwgfKNwgyUMPOuki2om/EY82m0RRQLo9oUtHUVwlJBZ4EYIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746821873; c=relaxed/simple; bh=QAQwoFDGTO2//ydxJPnSjPdvJrw2htDOdNuFU1aeSnY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BYBVdrcV+IgpfcxbEJq5iSTKKmy4qgy9ICSGwUBq1of1Q7B78D6tgu+9XmKkk65gp+HrifTuvvcg8LY8fOhQBZLInVs0rNQECXT5vwU9OOMZ7UFnKg29tyVpXNnVTDZR5sWQJIUOz1uMkSBOoQcaUfCzobeqrJ8HyiCpCdT7EVI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sGiLurQG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sGiLurQG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EAE9C4CEEF; Fri, 9 May 2025 20:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746821873; bh=QAQwoFDGTO2//ydxJPnSjPdvJrw2htDOdNuFU1aeSnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sGiLurQGtAdJZAcD7S6o214GCLdiq9s/FPQIfqbt3AOA8GLYMck9Cxt8fy87rVyAP LiWAnys0Qz2h5EfOdE8niGh/cL3xNyVSNrGcd7AsgNzMtJ0mCKXJlGPZUiaP23ZOKx EpZcvJJkemhgc0kWCVASTeifE4K1eudeauTEafm0RwYO/gsHSYSsWLg/uMvPmFQJcR o5chIPDRX/IkSR9uj1NoQziZV3/+omRWWgHh5ss1l2dMiI9PPdNLquAGuj3JoMe+ic 0B6F/tqnsgTEdLjQOJMlVKzDBz1odNK6RrIY9IXJiWANWah7hWpKKh+uBT88iSGvxA 2g9HmYh5XqM6w== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Petr Mladek , Miroslav Benes , Joe Lawrence , live-patching@vger.kernel.org, Song Liu , laokz , Jiri Kosina , Marcos Paulo de Souza , Weinan Liu , Fazla Mehrab , Chen Zhongjin , Puranjay Mohan Subject: [PATCH v2 13/62] objtool: Fix broken error handling in read_symbols() Date: Fri, 9 May 2025 13:16:37 -0700 Message-ID: <16c0fcf02cdce0b93666e853070086d5e40be0e6.1746821544.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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 free(sym) call in the read_symbols() error path is fundamentally broken: 'sym' doesn't point to any allocated block. If triggered, things would go from bad to worse. Remove the free() and simplify the error paths. Freeing memory isn't necessary here anyway, these are fatal errors which lead to an immediate exit(). Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 1c1bb2cb960d..b009d9feed76 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -492,14 +492,14 @@ static int read_symbols(struct elf *elf) if (!gelf_getsymshndx(symtab->data, shndx_data, i, &sym->sym, &shndx)) { ERROR_ELF("gelf_getsymshndx"); - goto err; + return -1; } =20 sym->name =3D elf_strptr(elf->elf, symtab->sh.sh_link, sym->sym.st_name); if (!sym->name) { ERROR_ELF("elf_strptr"); - goto err; + return -1; } =20 if ((sym->sym.st_shndx > SHN_UNDEF && @@ -511,7 +511,7 @@ static int read_symbols(struct elf *elf) sym->sec =3D find_section_by_index(elf, shndx); if (!sym->sec) { ERROR("couldn't find section for symbol %s", sym->name); - goto err; + return -1; } if (GELF_ST_TYPE(sym->sym.st_info) =3D=3D STT_SECTION) { sym->name =3D sym->sec->name; @@ -581,10 +581,6 @@ static int read_symbols(struct elf *elf) } =20 return 0; - -err: - free(sym); - return -1; } =20 static int mark_group_syms(struct elf *elf) --=20 2.49.0