Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp4106424pxm; Tue, 1 Mar 2022 11:21:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFI7EPo7tjOiH1jC1R3B7iijOnW7l5gnvvS3gVNUZTb/IJAN6G+pxZG+7Rp7WciMsOmeFJ X-Received: by 2002:a17:906:4ad9:b0:6cf:93f:f77e with SMTP id u25-20020a1709064ad900b006cf093ff77emr20531550ejt.558.1646162466166; Tue, 01 Mar 2022 11:21:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646162466; cv=none; d=google.com; s=arc-20160816; b=g7VkwkA5NKgld4vxq2VzD1xEsCaNAZeWVccSkRER3qLJNuk0UKX0PauEaeNrl0DCBo Ipf+HA8GuOCOvsoE74CynaziCcONTsNuz//jqRiMF2jPG48jpM0LvkMNDG1Ff5I/rjXS D3xscSA+4OmEPmhMgOsxfFoEUnxV1GZC4LOTssovKV6jhiuGq4DNpJMimtgXUKStIIC6 V7WynBNKwyfUI1ycVSCIBEdjKKW5nQZk1zSSwnakvdXB+oiU1cUvdYVF5/O1TvGpNTGG 7PHg3AL93hEgwZ7Ea57upYk+ruaK6UwYtMJDKa/50A1wPGBwiUiiYFWQTYd96edpbcMQ 4RdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3cfe6qkGcSTk1RLLa+OWFN4fepuY3Vm0o//7NItg80k=; b=bXb8wWOO4DNfLKoVUPVnDxAVOpTBQeYxjLjYoqq6TbmhF9scLmBnZ58V9ori5aiCkK Pt8nPvpXg0iOuj+XLDq0hS/t6hygD80Bem88n5tp4kfQ7+GZzF7p45k936UTyir3KWei AWn0YnATH55yACsjny6powLN7l4JfV9Njt8/q0UHuO0A+vE5bW8WJnaXKwnDniCQFhR2 RR9LaUgHCCmzFK8SMC4/7Sph35eivxwFGBky018qUbtRS+8raiLWKKFBDBg+sx0kCiHW huoccL/neyg+L8y7LLK/nMvhaTUxS9Hwoi3LGW5vCm4DTogXKMu3Y3dqILZ1OKGXMNHN 3w6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=ZDHeGa6s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a170906394400b006d08bd305b4si7847917eje.584.2022.03.01.11.20.41; Tue, 01 Mar 2022 11:21:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=ZDHeGa6s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231669AbiCATOF (ORCPT + 99 others); Tue, 1 Mar 2022 14:14:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbiCATOD (ORCPT ); Tue, 1 Mar 2022 14:14:03 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D3CE4C7B5 for ; Tue, 1 Mar 2022 11:13:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=3cfe6qkGcSTk1RLLa+OWFN4fepuY3Vm0o//7NItg80k=; b=ZDHeGa6sGg2fhed+n3/g+w7foh /0d+DSHa2vtmAZDb8nGYRBXH4MC8O2HeTavX0MEGL+cEaf8APOKP5rVsRE9pjz33xg+DO74KIW6wG gA/ubCLBSoSONsAnzav2ktAJ6BpVFXZWHiIShd58iax1wBy+cOGQXpzFARPBADdVIyaO9E5Cx1jVz LUxL6qlN/LCKiDSRK09bMpHALfZwVn9cHx23NlyMphmschKDJ+OEiI1N6Q7hR0nPoZG7g47TT4zjz FgVlgfuz+/XHwt9oUfTr1wA27/GYB8M2YKZymadyurPXSY13wBKbqTo7PelLeXJHur1wc61TWzblv aapZIZ7g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nP7vS-00ELny-N8; Tue, 01 Mar 2022 19:12:47 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 2409B986271; Tue, 1 Mar 2022 20:12:45 +0100 (CET) Date: Tue, 1 Mar 2022 20:12:45 +0100 From: Peter Zijlstra To: "Naveen N. Rao" Cc: Masami Hiramatsu , alexei.starovoitov@gmail.com, alyssa.milburn@intel.com, andrew.cooper3@citrix.com, hjl.tools@gmail.com, joao@overdrivepizza.com, jpoimboe@redhat.com, keescook@chromium.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, mbenes@suse.cz, ndesaulniers@google.com, rostedt@goodmis.org, samitolvanen@google.com, x86@kernel.org Subject: Re: [PATCH v2 15/39] x86/ibt,kprobes: Fix more +0 assumptions Message-ID: <20220301191245.GI11184@worktop.programming.kicks-ass.net> References: <20220224145138.952963315@infradead.org> <20220224151322.892372059@infradead.org> <20220228150705.aab2d654b973109bab070ffe@kernel.org> <20220228232513.GH11184@worktop.programming.kicks-ass.net> <20220301114905.e11146ad69d6e01998101c3b@kernel.org> <1646154463.4r1sh4kjf0.naveen@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1646154463.4r1sh4kjf0.naveen@linux.ibm.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 01, 2022 at 10:49:09PM +0530, Naveen N. Rao wrote: > Peter Zijlstra wrote: > > On Tue, Mar 01, 2022 at 11:49:05AM +0900, Masami Hiramatsu wrote: > > > > > - the 'offset' is NOT limited under the symbol size. > > > (e.g. symbol_name = "_text" and @offset points the offset of target symbol from _text) > > > > > > This means we need to call kallsyms_lookup_size_offset() in this case too. > > > > I'm feeling we should error out in that case. Using sym+offset beyond > > the limits of sym is just daft. > > > > But if you really want/need to retain that, then yes, we need that > > else branch unconditionally :/ > > I think we will need this. perf always specifies an offset from _text. The _text section symbol should have an adequate size, no? > Also, I just noticed: > > + if (!kallsyms_lookup_size_offset((unsigned long)addr + offset, > > + NULL, &offset)) > > + return ERR_PTR(-ENOENT); > > + addr = (kprobe_opcode_t *)((unsigned long)addr - offset); > > } > > This looks wrong. I think you need to retain offset to calculate the proper > function entry address so that you can do: > addr = (kprobe_opcode_t *)((unsigned long)(addr + offset) - func_offset); > offset = func_offset; Right you are, it needs to be: addr += offset; kallsyms_lookup_size_offset(addr, &size, &offset); addr -= offset; with all the extra unreadable casts on.