Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp271939lqh; Mon, 6 May 2024 20:24:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVEcIXcXjaBEuIyL+IxLj7NQm5JO1MZRaENPE87AAsnuJwYGi0mYNEvxQgYtm/ZhVj8VrwUu4sn/4CKRluEQzvnkKIdzvvaRTtgkGmadw== X-Google-Smtp-Source: AGHT+IGYRC2ANjx4pBR2ImSpMh+/SWeuDunoA305EDKNQX0Yj/OZKW39qTQCzl/X4R/YU4RK1tQd X-Received: by 2002:a17:902:7615:b0:1e4:b4f5:5cfa with SMTP id k21-20020a170902761500b001e4b4f55cfamr12845932pll.27.1715052255235; Mon, 06 May 2024 20:24:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715052255; cv=pass; d=google.com; s=arc-20160816; b=Ncw1ViugbD/1NA7RV+iUnA/x9uingonxS1xNmQOlRk3LcG/dmzGWxr6JoBqZqJDcip +VWu18m/Z1cGZP2VVXDxaEZ6nD0f4Z2FWQ5Kx16f0ri1ccYVeQftciJwk/94dH9ydT09 3+E8qWO6QkP/X1MQN0o9Bzf9GseoJzpytqbeUL7nVZZdya7H43qXLQMZXUj24d1gjbp1 qG7Z06a0exfVgAQbZSSJTpVyeedtx0h6KdWeo1sNscBAkDwr0Vik+OWHpfpQv0e5umaz zHsBfQ9QtbSVRgL0SEX9SeYafWA2gyIkkqaGHFcWJI0fzkMavnf/xBie+SrWUx3Wvbt5 TOAw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bckawV/2rW0cSrIRRBaDD28nOnQxAVVfXpcr4MEHb7I=; fh=uLqGWw6lyhj3sgP0EDrc2QOiIxEyl5lGhi1aaReL8MA=; b=Csk/VbF9UZ7WizjwQKC7Qns1YaOOYmmDevk1naWv5P88wvguwNVMdFTZksu0k9vBMs CHLpR/MRdprDq4F5RViRqnIqvQrJGi+SSXENDAvaOPgaOLGhCJ5bmmjjvG8Kqd/reyoD 0pCIL0pg6LFklUUqsX5ctk3pOwkJji/3l/zt4yGec+8QuJ+hQzkxWeiFN37dYxhtsHV2 5nh1KjeY2V8DV3BxWCtsFwDRSuCeGd96LsjcU7yPeBXHYAhDfLf/DLYx7IejPuPglOAt 1k2L0GknoUYNDx2mCI1C9ZLZiVLyRkF0ICe+SmSxIcdYNkgG/epefbukpn1+SyLRBk4P cYvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ELeABIZq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-170610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p14-20020a170902780e00b001ec32171d08si6549312pll.290.2024.05.06.20.24.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 20:24:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ELeABIZq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-170610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2ED27280E35 for ; Tue, 7 May 2024 03:24:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F01A3FBA2; Tue, 7 May 2024 03:24:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ELeABIZq" 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 C19D73D0BD; Tue, 7 May 2024 03:24:02 +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=1715052242; cv=none; b=I+u4j2ovYGYykBO8ak6+fm0582S+CyKWiAmS/TAMXbowV/jMu4CRhZdjgYmKpSKsizgsz9Ik13rpOJk2Ou2Dits29nRWZzAfOSvWbQoKkRlKNkzdW1109jDrUTh5FdsOk6W45bwg5yonclfI3Qevo6HAB73rl+xZm0ZbVduTgUg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715052242; c=relaxed/simple; bh=wwRDMK2MTHyfmFutWwVpB0wuAlNULl9BsyJ4npcXu/8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AF57CQ3nyyAI18P5cAWbvbQTnBNC9oxuYqKsIRoQslhJqQzbZHY+CKZWUvElRXT2Gk9gYER0Wt2Yf2ch2rOr9KtR6FsDtgsh37SbUFtLIERP2J+mJvu37/XfCyH2P+kwU9ppAzRo5PJBUOGCTs/SuNt0O5XSQFKhccaxFdYIeNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ELeABIZq; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31A14C4AF63; Tue, 7 May 2024 03:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715052242; bh=wwRDMK2MTHyfmFutWwVpB0wuAlNULl9BsyJ4npcXu/8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ELeABIZqtUy5w2w+CIgX5YOv+COx2TwYQUIsI3SescFNSB292IcSt+SPewSdMlnfn Ikq5cZJzk3eQFXGpXj6LHOickkuBaI6J1/GsVYxxrRnBInOlmk+XOTWyazhYZLmeiF b32PBXwe/tMzdiS5zviboUxiBHYzgIwfhzuuhDjqpd1PqzgNVgaMQN7LepaZypY6Cq I5QB8ZlGHhdaCiVzggV33hdBFqgxxx/6/oe1kmWeTNipIiRPbYYhDjwpBq98j/EHu0 EeWKQWw1/wW5/0uLj3YIcLigubjqTFJYoc+iuj3QZK7mU0YdhqPwQ8qT9w61FHADpq jMYKPMQQ6Crcg== Date: Mon, 6 May 2024 20:24:00 -0700 From: Josh Poimboeuf To: Kees Cook Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] objtool: Report section name in elf_init_reloc_text_sym() warning Message-ID: <20240507032400.gxorrjm3q7mg5cac@treble> References: <20240506155537.it.760-kees@kernel.org> 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-Disposition: inline In-Reply-To: <20240506155537.it.760-kees@kernel.org> On Mon, May 06, 2024 at 08:55:54AM -0700, Kees Cook wrote: > While tracking down issues with LKDTM's .rodata "function", I found > the warning from elf_init_reloc_text_sym() to be unhelpful because it > wasn't clear which calling path it was coming from. Report the sec->name > and rephrase the warning a bit. Additionally check for NULL sym->name, > which may happen. Hm, as far as I know sym->name shouldn't ever be NULL. Though, looking at this code again I'm realizing that 'sym' could be NULL because it refers to the symbol for the function's *section* rather than for the function itself. And sometimes the toolchain doesn't generate symbols for some sections, if they're not referenced anywhere. (Note the code immediately below your patch actually makes a section symbol if it doesn't exist.) But also, this warning doesn't even need the section's symbol. It can just get the name from the section directly (insn_sec->name). And it would probably also be useful to print the offset (insn_off), like ".rodata+0x1234". Though, even better, we have an offstr() helper which can pretty-print the name of the function or variable, if one exists at that address. tl;dr, does the following work? WARN("%s: unexpected reference to non-executable '%s'", sec->name, offstr(insn_sec, insn_off)); -- Josh