From patchwork Sat Jan 7 05:14:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Joan_Bruguera_Mic=C3=B3?= X-Patchwork-Id: 40313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1166968wrt; Fri, 6 Jan 2023 21:23:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXswRFCwEkp5i1dYc2bQeBMO8uXs8i424zBHbPJc90tL8cdFR/4XvCASiVmPEcODCLlNfITr X-Received: by 2002:a17:902:b407:b0:192:bdf8:1a58 with SMTP id x7-20020a170902b40700b00192bdf81a58mr21079619plr.50.1673068984911; Fri, 06 Jan 2023 21:23:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673068984; cv=none; d=google.com; s=arc-20160816; b=nNhO2rnCRLi4fVJIW32ieece6Qn/rnZgTPYD1hvmbQEtYGuYcNItVXItKRIHo2qWT5 h6lyRcPCPHW8+gXhtCzxxl1A1XQvzQDh+QS00XjVFquO+kKh4DF9amIaFjFC7MTOvnCj mIqS3VJr6mXkkS6kEIk5mfoLE4Jjtnk3w8pA4NOOBLjJeRjgYh+LqWVF7ZQ47xcKoZXS c6snWcibPjQdiRUWUHRsBXobSIOD0kUBI5xyiIo+lrjr7jUiLQ0PT0XfNnUXh2C06BlE jcNfWRDnNAtHrDjsGO0dtBa9Tvh68vMelPW7u/BK5uiKXWn/Qog5b/T2GzGqnyvfTLZj rvhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=d0akaezmMiUg9uY87rK2hSkPM/8hryZ13zAkpajBo1g=; b=fRRv3+xBlehBqO3RGu5/Qo1hlIIasnSB74rEJtjymALKpS7qrcRILCvrdFgpm8+ng9 YA9o7nxER3jobCG6NjdxhtCzxBM8OAX+Z2QHV8hjy/0eA2geCyt/p7lJ2Ae7rX1XsjsV eP9ovDNDXJAr8ALftFesznpCiuM7Qz8gB8BH3bq2F7tywfOVCFg+Y8IKDV8MbgGkB+bb lE9Se9CTEGK8oCi90NByP5viamdadiYWWEyl4V4UB06GC1reJYKmwFo1eXmCXC23ruWh fuPD7/GyvuWDOF+Bh+dwrc97K4h6Stl70JA5vS5EOVVSs3/2ulaI0xGa/kNlJZdRJIO9 GVkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Jsx96CNq; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a170903124c00b00189ed8594bbsi3210882plh.64.2023.01.06.21.22.46; Fri, 06 Jan 2023 21:23:04 -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=@gmail.com header.s=20210112 header.b=Jsx96CNq; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229550AbjAGFPF (ORCPT + 99 others); Sat, 7 Jan 2023 00:15:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjAGFPC (ORCPT ); Sat, 7 Jan 2023 00:15:02 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6712361322 for ; Fri, 6 Jan 2023 21:15:01 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id bk16so3015407wrb.11 for ; Fri, 06 Jan 2023 21:15:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=d0akaezmMiUg9uY87rK2hSkPM/8hryZ13zAkpajBo1g=; b=Jsx96CNq8CWFQsfh1mk6L2VZrfLDChqOWew/XF9THQ47cIcO8aZGNiJ2LaALuNJ3pp PQbx4LbNHLtGeAbsjXDtYPXmLiZBLKbTugjm99XsrorC57HoV3GjqTTW4OKtiiVRGcnp nH4DbTN/Z8FgeTz+lFaVuL+LbG1a02NHXb1HDeuMjG9kg1biY7Q3DoZQ5ftqpeEAYcJE 202Of0E/Hr+bKZjZZbohKT5iyrAr6tZjZ+r7GP1tsWDZC5l4sKqo3EllqSvVlZiQneqC OrgjY42TXPDI/B21RW4wKLqGSI6jugMo3bkZv57420GNOC0MCBo+lSuroGv2oV88VbPi XEmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=d0akaezmMiUg9uY87rK2hSkPM/8hryZ13zAkpajBo1g=; b=VKMX76XoPTM0jLOIm/6Q9FvaVpn55FYakCelDlFf2eMHa6L+Zr8GPkW6gDNzfVM9pZ mxofrMTYL0YY0lInZy8kvo30eRUIA4KaxmNiLlwQwWaFB2Kr+U6C5F6xguvLN2G2xBB8 6X6E8Hlt/aA7z8ZMIsfeJ/c4qu8XCSqLiWl7vpE1xSs4ugKb61oHjNYFvUX2DSK3kcqJ Qn8lFBepwIzjW0GlmKIo2xtex6fLh9QmRllxxoqAuCwow47fMesXhHouIUaVnyncY99Z JGL+Ncb4c0UUNw3ZkqWh6mWwInWEVaXI/JQ83ZJFfKZegOMV8RKdYHiAYHCcFEVjc0D7 hqoA== X-Gm-Message-State: AFqh2kpE5jgPOeImkjyQIl/ag6eLlHei9vKKR90SGGjJWjTSEHfF9zdp aIm6qlXl/srkrTeQCdUW7cU= X-Received: by 2002:a5d:4591:0:b0:2b4:790e:32f8 with SMTP id p17-20020a5d4591000000b002b4790e32f8mr3901075wrq.48.1673068499705; Fri, 06 Jan 2023 21:14:59 -0800 (PST) Received: from solpc.. (67.pool90-171-92.dynamic.orange.es. [90.171.92.67]) by smtp.gmail.com with ESMTPSA id c18-20020adffb52000000b0025e86026866sm3354017wrs.0.2023.01.06.21.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 21:14:59 -0800 (PST) From: Joan Bruguera To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "Peter Zijlstra (Intel)" Cc: "Joan Bruguera" , "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [PATCH] bpf, x86: Fix IP after emitting call depth accounting Date: Sat, 7 Jan 2023 05:14:56 +0000 Message-Id: <20230107051456.8800-1-joanbrugueram@gmail.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754339984176975483?= X-GMAIL-MSGID: =?utf-8?q?1754339984176975483?= Adjust the IP passed to `emit_patch` so it calculates the correct offset for the CALL instruction if `x86_call_depth_emit_accounting` emits code. Otherwise we will skip some instructions and most likely crash. Fixes: b2e9dfe54be4 ("x86/bpf: Emit call depth accounting if required") Link: https://lore.kernel.org/lkml/20230105214922.250473-1-joanbrugueram@gmail.com/ Signed-off-by: Joan Bruguera --- arch/x86/net/bpf_jit_comp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index b808be77635e..6e696c6b7018 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -343,9 +343,10 @@ static int emit_call(u8 **pprog, void *func, void *ip) static int emit_rsb_call(u8 **pprog, void *func, void *ip) { + void *adjusted_ip; OPTIMIZER_HIDE_VAR(func); - x86_call_depth_emit_accounting(pprog, func); - return emit_patch(pprog, func, ip, 0xE8); + adjusted_ip = (u8 *)ip + x86_call_depth_emit_accounting(pprog, func); + return emit_patch(pprog, func, adjusted_ip, 0xE8); } static int emit_jump(u8 **pprog, void *func, void *ip)