Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp479252rwd; Sat, 27 May 2023 00:45:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5bht1hTAGhk6cw8rUy6zPhbpLDebMuPw37hO8G9KMUahaUGPdYRuhfF3nZjfRzzAOXSmmh X-Received: by 2002:a17:903:1d2:b0:1af:b7cd:5961 with SMTP id e18-20020a17090301d200b001afb7cd5961mr6439203plh.1.1685173505503; Sat, 27 May 2023 00:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685173505; cv=none; d=google.com; s=arc-20160816; b=FmegkAHD/D1o4XFfIZN6HxrbNEEJFxPZpV+oAAn/jIH1hlQ5Mh1JKszdJsKShrX77n Jt/bTokLWveIkukpziWnyjDWZmbvZuEZhlvZT2RaIR4swPmsq934+7m14toxTzm2avOU DjJFr9ECs6SLw2sVItSuilSBiQoGPedmgB4dQiK8teK1C2ow3ZcTG4WcFZePuivqIULU OQoXp0dRoqmp9AKAvIgDW9Ng9hjA0VCMkOOHg20iq9/py3nEjnCahbUiuu3nR36gyPHq EA5bgO1yU9gcwCxmDWIMPZcfdGLfvcS6uTxkTNO0ze2TegcsleEwvHFO/ia9/8ajkv8D /WDQ== 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=EccVBHabIGbLCtNLMzuwGkc2JriX9LRyjMLOs3mmoA8=; b=dSXl1r3zwgguA6X6HDtPgvnj+Ewo3hEg5HT5wrNZtBnUEbbnhcrZE5SjQANICWlAl0 h6IpV9qYYQJtBb/idHL/WLvhF4MQ+KrPZ5ertCuGCTsL0fnLRuLqfOqOux/mPSyAfvNW o6gStpiGLXS1ftWpqEo7xAUkrg2/LyEGjSwS8gws4wLq36AgJJweABOekfKjs7t4CO5b BK2Z9L9ck1O1GhrkBL+tVeaoAeKtedMYNrlDtwgde6FS4koelRqRGXCsD3Y6Vja0d7sd THmz4CSD+sudATRrDxettgNfmrzpaKdIsomF9529rKj7QhJqM+4DwYhB66iz9uLM0qJB z11Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@alien8.de header.s=dkim header.b=kXgGNvfH; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a170903228b00b0019a96849d6dsi6225049plh.605.2023.05.27.00.44.51; Sat, 27 May 2023 00:45:05 -0700 (PDT) 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=temperror (no key for signature) header.i=@alien8.de header.s=dkim header.b=kXgGNvfH; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231550AbjE0Hgd (ORCPT + 99 others); Sat, 27 May 2023 03:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231995AbjE0Hg3 (ORCPT ); Sat, 27 May 2023 03:36:29 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAD2DC9 for ; Sat, 27 May 2023 00:36:24 -0700 (PDT) Received: from nazgul.tnic (dynamic-002-247-254-198.2.247.pool.telefonica.de [2.247.254.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 234DD1EC06EE; Sat, 27 May 2023 09:23:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1685172224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=EccVBHabIGbLCtNLMzuwGkc2JriX9LRyjMLOs3mmoA8=; b=kXgGNvfH0DlUJsqtiJyX/1TSZnRDd3rvn5RoA+gW1pqEMT/2bX0UNw59y4Ytuwc4DZXwKs wgkgjNCjkusAHdg7u4ahUGS2mMUvnO36aC9rhyxZN8xkHg3tMjdW7Fc8fBt8+VpmSLN7dz Vh+hPRXEptCW27fYwV3Rqt4UrLjoiCs= Date: Sat, 27 May 2023 09:23:38 +0200 From: Borislav Petkov To: Nadav Amit Cc: Dave Hansen , Jiri Slaby , Thomas Gleixner , Ingo Molnar , Dave Hansen , X86 ML , LKML Subject: Re: [PATCH v2] x86/lib: Do not use local symbols with SYM_CODE_START_LOCAL() Message-ID: <20230527072338.GAZHGv+no2LZASyLWM@nazgul.local> References: <20230525184244.2311-1-namit@vmware.com> <38e24fd4-9213-229d-9919-7ae3bfb113bb@intel.com> <24E47178-C177-425F-A8EF-CFFAE22597D4@gmail.com> <20230526155336.GAZHDWAFi1FRqq83TP@nazgul.local> <0F07EEDB-8A3F-4224-9FF1-43A5300B1B8B@gmail.com> <20230526204559.GAZHEahxxnQaHhSUul@nazgul.local> <49861038-B8CA-4CDD-BD44-73066FF453F3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <49861038-B8CA-4CDD-BD44-73066FF453F3@gmail.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Fri, May 26, 2023 at 02:55:21PM -0700, Nadav Amit wrote: > So my tool takes a branch trace and then simulates the code execution. > As a preparatory step I need to disassemble the code, yet as I do not > know where the symbol starts and its size, I can only disassemble one > instruction at a time. [ I prefer to disassemble the whole symbol at once So in this particular case, the exception handling ends up being part of __get_user_nocheck_8, see the end of this mail. However, the symbol table says it is of size 19: 123630: ffffffff81b89310 19 FUNC GLOBAL DEFAULT 1 __get_user_nocheck_8 which means the trailing exception handling is not part of that symbol when looking at the size. And that's where your tool fails. Close? And if so, your tool could simply look at the next symbol's address and attribute the trailing bytes to the previous symbol. If you look at the disassembly at the end, some other option has added INT3 padding to the end of the symbol so that the next one is aligned. But you can simply skip over those 0xcc insn bytes. And skipping over those 0xcc bytes is something your tool needs to handle anyway because they're not part of the symbol either. > These are only 2 things that break to one extent or another. I can > have workarounds for them (I already do). I just see no reason to > treat these two symbols differently. Right, the kernel should not dance just because some tool says so. And every time a new tool pops up, there are patches to "fix" the kernel. > I seriously see no downside The downside is polluting the symbol table unnecessarily. If it doesn't have to be there then it shouldn't be. And yeah yeah, this particular case can be fixed easily but the bigger issue remains: we have a lot of local symbols which get discarded around the tree. Does that mean that because your tool cannot handle that, we have to stop using local symbols? What happens if we do something else weird in the future and your tool breaks again? Also, why can't your tool handle such cases gracefully instead of having to "fix" the kernel each time? Thx. ffffffff81b89310 <__get_user_nocheck_8>: ffffffff81b89310: 90 nop ffffffff81b89311: 90 nop ffffffff81b89312: 90 nop ffffffff81b89313: 90 nop ffffffff81b89314: 90 nop ffffffff81b89315: 90 nop ffffffff81b89316: 48 8b 10 mov (%rax),%rdx ffffffff81b89319: 31 c0 xor %eax,%eax ffffffff81b8931b: 90 nop ffffffff81b8931c: 90 nop ffffffff81b8931d: 90 nop ffffffff81b8931e: e9 9d a3 01 00 jmp ffffffff81ba36c0 <__x86_return_thunk> ffffffff81b89323: 66 66 2e 0f 1f 84 00 data16 cs nopw 0x0(%rax,%rax,1) ffffffff81b8932a: 00 00 00 00 ffffffff81b8932e: 66 90 xchg %ax,%ax ffffffff81b89330: 90 nop ffffffff81b89331: 90 nop ffffffff81b89332: 90 nop ffffffff81b89333: 31 d2 xor %edx,%edx ffffffff81b89335: 48 c7 c0 f2 ff ff ff mov $0xfffffffffffffff2,%rax ffffffff81b8933c: e9 7f a3 01 00 jmp ffffffff81ba36c0 <__x86_return_thunk> ffffffff81b89341: cc int3 ffffffff81b89342: cc int3 ffffffff81b89343: cc int3 ffffffff81b89344: cc int3 ffffffff81b89345: cc int3 ffffffff81b89346: cc int3 ffffffff81b89347: cc int3 ffffffff81b89348: cc int3 ffffffff81b89349: cc int3 ffffffff81b8934a: cc int3 ffffffff81b8934b: cc int3 ffffffff81b8934c: cc int3 ffffffff81b8934d: cc int3 ffffffff81b8934e: cc int3 ffffffff81b8934f: cc int3 ffffffff81b89350 <__pfx_inat_get_opcode_attribute> -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette