Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2769561rdb; Fri, 8 Dec 2023 20:52:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsdP5+mgHW0ArqN9fuMAQKKzuT5Y9FwfFr9GOB69GzOh5L2JBT0kCLNu+Cy+zEyiVGed0L X-Received: by 2002:a17:903:11c8:b0:1d0:68a:4a46 with SMTP id q8-20020a17090311c800b001d0068a4a46mr1261575plh.3.1702097555068; Fri, 08 Dec 2023 20:52:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702097555; cv=none; d=google.com; s=arc-20160816; b=Q0eLn/BBbWxrb2kRSERIEwcB/UahSmcMcjQnDyHXEjrpglM6JqxPJWRN6SZg0g8rph vlF0WGaMtFCWu8dbDS44TGFLocypyrX3gSf/gyNOHlZ59e/CeyWh23L5GfSlepd+RZzW Rq1B/kqYU6JZDpAjeTkCN1n2dBuK3ygM30/jti2OYMmHnZG/zOm5ozCcsuVrZRbMDUWH 4iGc/b1NBoSc0KV4ryzeop+NLLLImIBd8LQiI3OxAU8A2Qu+TQU/FHfdtrREyzI/3oBe S4gZ6P0Pb6R37pENDYRii0yLSBOQcO5g0Ns+EcAsIDk/WhzkAUBJud8gYEJuQUa3RZCT u9+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=E9jLsGhfGkMZnWhDYfHQ0jvQvXqjfciOlusSLK9GhRY=; fh=fQgCWRvTCP/t++nK1ImfffmCDgAeoMpK4D1rM2RjSwU=; b=YUvZ1NdQ7BwmWaOB2HCOg8OFQWMW2ZgEMl+vt0vjOA0QiErhov9UL+mRnht4Wzx6JM pVThFVg93Puu5Ya6ymudZotayl7xaa1wzbowXd6ennDqLolUzlHD1Iez6MvFqIFunKoD UwwKtnjWaqiNmhF+UxNj/PQTWBsxNM7rp4keioxj5GFNNLLxNcDkXk5Dh79jC2yVSUir cfoO9db2/6Abwl+rWFwYSfmAtqIFM9Tkk1IRgPfzNU9TmpXLjsX44yNENxHE1GMmsm8W 2uDMcBmS8Vt0FVXFmLPNdVVpsZ7fxKGhYBXBdpRA0/uu/DwlvIRUtUTrf/ky9FMpXPEF xZhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KeESuLTe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id a6-20020a1709027d8600b001d08c079196si2567593plm.36.2023.12.08.20.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 20:52:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KeESuLTe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 2F73F8051A18; Fri, 8 Dec 2023 20:52:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234272AbjLIEvh (ORCPT + 99 others); Fri, 8 Dec 2023 23:51:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234264AbjLIEvf (ORCPT ); Fri, 8 Dec 2023 23:51:35 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8E9110DF; Fri, 8 Dec 2023 20:51:40 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-332fd78fa9dso2566897f8f.3; Fri, 08 Dec 2023 20:51:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702097499; x=1702702299; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=E9jLsGhfGkMZnWhDYfHQ0jvQvXqjfciOlusSLK9GhRY=; b=KeESuLTeX8T5ede0i/kSECpSnduJslTf/82J4Z57rkWkSf8dSMVICt52nYkMFTOITW 099C3aWGMtSw770fNLMxYbnj8Flv7HGJMeJpx8n29C0BMB+kz4LKbf26wUiYEVblcqIV eJ8kmYDYcNE8tfSblEWCCPuvlQ3sIoo3DhX/ssxWrC8rnhS9czhqJAmkrmA9WOD3ILP1 o3Vj1z3dABjSQA3jPb9x9rm6dDK+EO1NpB+Sb/FmhNhAwpJM4qECPWTrf5YHCr/+8iNw puYmU9Fvq4imcj/3AzNgZ4XiuRgkS2XibAg3jB69haE6GgMTNRlrxNG9Dehpb6ffErJ/ KmPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702097499; x=1702702299; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E9jLsGhfGkMZnWhDYfHQ0jvQvXqjfciOlusSLK9GhRY=; b=AeMAll1+7Hm+LqvEgTNXH0lzxGQd4etsowOeyJqcehBysYX5I4uc9Bn/MeYGzNIATK yLBMYbR/TPVfdBazATRCdYDkV5ACWwR+DXXvHkqlbdHklegH/ug7DMclYdEl5i5VGRDx ItNK+dxzOLR7/4oRJqk6HKC/c2A5dskk82CsyTfZENAtSPjwXavvsj1JN/NWcykxBhJM px07D4wQwEGJCLANU0RO1ophOJr/50eKInDah80Nmivxk3tPQgSDR5VWVLYRklF8CeRd sXN1uGZoP2G5QVErF5YbJ4tN0PJeDUkmEsZUSFnaBK4cXauohmYLCv+04+rHD78zjNB9 1+eQ== X-Gm-Message-State: AOJu0YyiAm7KxmTwW4K2yvhry/jBGf0KDBa9HkklvsuoE/W6DggJA4xe b2VWKJndrwX0/dEB2ZjxJB8qBxffeQ0xqXUlzbc= X-Received: by 2002:adf:ce8d:0:b0:333:49a8:73e4 with SMTP id r13-20020adfce8d000000b0033349a873e4mr197659wrn.201.1702097499187; Fri, 08 Dec 2023 20:51:39 -0800 (PST) MIME-Version: 1.0 References: <20231207093105.GA28727@noisy.programming.kicks-ass.net> <20231208102940.GB28727@noisy.programming.kicks-ass.net> <20231208134041.GD28727@noisy.programming.kicks-ass.net> <20231208172152.GD36716@noisy.programming.kicks-ass.net> <20231208203535.GG36716@noisy.programming.kicks-ass.net> <20231208205241.GK28727@noisy.programming.kicks-ass.net> <20231208224557.GH36716@noisy.programming.kicks-ass.net> In-Reply-To: <20231208224557.GH36716@noisy.programming.kicks-ass.net> From: Alexei Starovoitov Date: Fri, 8 Dec 2023 20:51:27 -0800 Message-ID: Subject: Re: [PATCH v2 2/2] x86/cfi,bpf: Fix BPF JIT call To: Peter Zijlstra Cc: Jiri Olsa , Song Liu , Song Liu , Paul Walmsley , Palmer Dabbelt , Albert Ou , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "H. Peter Anvin" , "David S. Miller" , David Ahern , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Arnd Bergmann , Sami Tolvanen , Kees Cook , Nathan Chancellor , Nick Desaulniers , linux-riscv , LKML , Network Development , bpf , linux-arch , clang-built-linux , Josh Poimboeuf , Joao Moreira , Mark Rutland Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 08 Dec 2023 20:52:32 -0800 (PST) On Fri, Dec 8, 2023 at 2:46=E2=80=AFPM Peter Zijlstra wrote: > > > Ok, did that. Current patches (on top of bpf-next) are here: > > git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git x86/cfi Looks really great. The last patch is cleaner than I expected. Good idea. > (really should try and write better changelogs, but it's too late) commit logs look fine except the "pilfer" word that I had to look up in the dictionary :) > [ 247.721063] ? bpf_throw+0x9b/0xf0 > [ 247.721126] ? bpf_test_run+0x108/0x350 > [ 247.721191] ? bpf_prog_5555714b685bf0cf_exception_throw_always_1+0x26= /0x26 > [ 247.721301] ? bpf_test_run+0x108/0x350 > [ 247.721368] bpf_test_run+0x212/0x350 > [ 247.721433] ? slab_build_skb+0x22/0x110 > [ 247.721503] bpf_prog_test_run_skb+0x347/0x4a0 > > But I'm too tired to think staight. Is this a bpf_callback_t vs > bpf_exception_cb difference? Yep. It's easy to fix: diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 0e162eae8639..e36b3f41751e 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1484,7 +1484,7 @@ struct bpf_prog_aux { int cgroup_atype; /* enum cgroup_bpf_attach_type */ struct bpf_map *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]; char name[BPF_OBJ_NAME_LEN]; - unsigned int (*bpf_exception_cb)(u64 cookie, u64 sp, u64 bp); + u64 (*bpf_exception_cb)(u64 cookie, u64 sp, u64 bp, u64, u64); #ifdef CONFIG_SECURITY void *security; #endif diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index fe229b28e4a9..650ebe8ff183 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2537,7 +2537,7 @@ __bpf_kfunc void bpf_throw(u64 cookie) * which skips compiler generated instrumentation to do the same. */ kasan_unpoison_task_stack_below((void *)(long)ctx.sp); - ctx.aux->bpf_exception_cb(cookie, ctx.sp, ctx.bp); + ctx.aux->bpf_exception_cb(cookie, ctx.sp, ctx.bp, 0, 0); WARN(1, "A call to BPF exception callback should never return\n"); } and with that all of test_progs runs successfully without CFI panics. *happy dance* Only test_progs -t btf/line_info fails suspiciously. There we check that line info embedded in the prog looks sane. New cfi preamble is probably tripping something. It could be a test issue. I'll investigate. It's not a blocker. Do you mind resending the whole set so that BPF CI can test it on different archs ?