Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1098508pxm; Wed, 23 Feb 2022 18:05:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyqaNkCNBu4efAwr/9NuFM0x/pow+XLXdDPEbpxCYgM64JFwqhrWl/Mpke8WTPkYzwvWPYR X-Received: by 2002:aa7:8d54:0:b0:4e0:bd6:cfb9 with SMTP id s20-20020aa78d54000000b004e00bd6cfb9mr395210pfe.60.1645668346968; Wed, 23 Feb 2022 18:05:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645668346; cv=none; d=google.com; s=arc-20160816; b=e1lpDInam3APptz9uDA/y7d/0Sx3Xtb6URJT2xp7+UHgaRlf4yBPdSTmThs6DzPd7I Y2ILM45kfhQ9UkcT1te16fFTmCwyvdOJ3M6G77F+ixBgbsrO/kGRA0EKuZYpol4UBJVc THOvw0Ft0he+1hAoPwd2xo+QukMF5EOgNZTFk9ph1GMhVBYf4wd3vFAl3QH6TpoS0tyr 1+KAOzHP2eFYGbNUlHwAjT3RQMo7uBqs8WxIWatFjmintpQA/aAOrS2EEAn9hPPkp5UQ Y9gzVjkYQUbKrX2RhCB3BOjXgJWxz6zH9vmP/8fE81CuTohsHRhJRGsf91ezyNNR0R4L rHrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:references :in-reply-to:subject:cc:to:from:date:mime-version; bh=sJa3QOKgPE31taCsfpXa2Y7dMKpSAa9Xu2XPuUBX+9Y=; b=UOrfLx1oydlDOnJHSb1HQ0iQet4E/VFJ7gF/fGl+cBJNDXQj3w8yy0sI4AzYpNvDaX p78TcCAQ0bHMgyN8rXJGuA0oeoYLi+DuUD2v03FkG42LzlbXwLOn3yIiY2wAsLTKxSa1 47AvDRib+T6sDWXv5di3o8E2PJZUzIHwxX103SHwvp+PN/1LxcguJQENxKxge39J0Rus klNkaIkEcHqf5u+t08rBWNP8eozGeSYCXN1KDRaRsgawln4jesoul6Qi0C466YhqH2qE tUh3/o9Qn238hSvK5cTcYSknKZKIoBaxHQkknOlIDxf1FlFXnkqEYkAJ7jdrslI3CO2t CRCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p4si1227257pgs.294.2022.02.23.18.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 18:05:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B52DF13CEE7; Wed, 23 Feb 2022 17:34:52 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbiBXBfQ (ORCPT + 99 others); Wed, 23 Feb 2022 20:35:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbiBXBfP (ORCPT ); Wed, 23 Feb 2022 20:35:15 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0311013AA30 for ; Wed, 23 Feb 2022 17:34:46 -0800 (PST) Received: from relay6-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::226]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 9F320CFD62 for ; Thu, 24 Feb 2022 01:18:47 +0000 (UTC) Received: (Authenticated sender: joao@overdrivepizza.com) by mail.gandi.net (Postfix) with ESMTPA id 1C897C0003; Thu, 24 Feb 2022 01:18:04 +0000 (UTC) MIME-Version: 1.0 Date: Wed, 23 Feb 2022 17:18:04 -0800 From: Joao Moreira To: Peter Zijlstra Cc: x86@kernel.org, hjl.tools@gmail.com, jpoimboe@redhat.com, andrew.cooper3@citrix.com, linux-kernel@vger.kernel.org, ndesaulniers@google.com, keescook@chromium.org, samitolvanen@google.com, mark.rutland@arm.com, alyssa.milburn@intel.com Subject: Re: [PATCH 24/29] x86/text-patching: Make text_gen_insn() IBT aware In-Reply-To: <20220218171409.990016403@infradead.org> References: <20220218164902.008644515@infradead.org> <20220218171409.990016403@infradead.org> Message-ID: <5c77889ca6b988b0dff65136264bd1fb@overdrivepizza.com> X-Sender: joao@overdrivepizza.com Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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 > +#ifdef CONFIG_X86_IBT > + if (is_endbr(dest)) > + dest += 4; > +#endif Hi, FWIIW I saw this snippet trigger a bug in the jump_label infra where the target displacement would not fit in a JMP8 operand. The behavior was seen because clang, for whatever reason (probably a bug?) inlined an ENDBR function along with a function, thus the JMP8 target was incremented. I compared the faulty kernel to one compiled with GCC and the latter wont emit/inline the ENDBR. The displacement I'm using in my experimentation is a few bytes more than just 4, because I'm also adding extra instrumentation that should be skipped when not reached indirectly. Of course this is more prone to triggering the bug, but I don't think it is impossible to happen in the current implementation. For these cases perhaps we can verify if the displacement fits the operand and, if not, simply ignore and lose the decode cycle which may not be a huge problem and remains semantically correct. Seems more sensible than padding jump tables with nops. In the meantime I'll investigate clang's behavior and if it is really a bug, I'll work on a patch.