From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98349C2BA18 for ; Tue, 18 Jun 2024 13:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FcnMHtNdVwEgRHhVzwaKzsGpucVSC1MxgjxGj0kWT+Q=; b=rXRyz+a3VhdsF5CeEWBxjr5+5h B7Xq+kaq14k9vcdtDZpIQDyNWJQ/SdX2su9IpuBjlk1+1nIIGN4FrdzhPj3nXjzMcMcx2Nn0yxHXn jeQ0dyuLfKKm9fmavLxyy5+KlyVB/+C9Gq40yMKhZqXwqkjLpgf4yA80Fe39XQvkPppQgRj/3Nw8C EjnsY10BORWe6EC0PpIlBSGDCh6FSS45WQSCoHqaFBRJVLm9o10u4FQiWUraSdI+f76hHHoXLXiK2 SWdmIlbVw1i2UvWcyWktP/S0ANtzagr5EC2ex8FgxfcpfnqdEINMzkJpZJEHVEtSbM2Zmb+QQ4pjh fJ3yNSaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJYvP-0000000F8r9-14du; Tue, 18 Jun 2024 13:31:03 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJYvG-0000000F8my-1OPO for linux-arm-kernel@lists.infradead.org; Tue, 18 Jun 2024 13:30:55 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4218008c613so41224465e9.2 for ; Tue, 18 Jun 2024 06:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718717452; x=1719322252; darn=lists.infradead.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=FcnMHtNdVwEgRHhVzwaKzsGpucVSC1MxgjxGj0kWT+Q=; b=Div4qtyWl8ilIQmn04jpqG/jdMuIq9to8ZX/fP67suKnYb8stiJgcY5oFNjHzm3D+9 63TjKHWvCwnJMt+5YrMrMO1JX1mmDWfT7xxT+HnGUB93J1zNPnozgbgAqpXWU3h9wh8a qcrRlqnoZuO+DONiTgDeVvKaEXHsLgSHp7BUad4SIIfNAf7nyT4kenoKRdjHylUuIVIm nH8YkEfILIxbGoTKU6cV4MmWL2JtMidXRqgPzTf69SOl/V5Uk74opV4FVpi6y9vl28PD l5rwdYOC8ee4dZ5neJTUjOn+ceaT/BWlBpcYdZV6KiIVBIh474oGpEEHRjB+aucAv8cS p2Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718717452; x=1719322252; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FcnMHtNdVwEgRHhVzwaKzsGpucVSC1MxgjxGj0kWT+Q=; b=v9zHAHhQlCzlCMIldfHgGVYkibX4tke3DEqSTZWnDoCqlR3kwxkFuYz/6/R1ur6mdq 9yXOsgIyoRPF4wfce1ktTtcyt4p1NgaSkxPBlm3hNMNS+6IU4tpfhw2IC2ni6psDZSFu h4l0z4XP/xC6WHi8+Ni8WqMrhRIeXtaCPW+H6lR3QEFRVN3uKV3zY0X5MTs7NZnTFotM E8VS1DFO2n7kvn9wc8MEJIAgZPd57VSnMzmql/s4jNRupdLSoOjHDGuJoEzxJy1bwwuT r0y/bHjD3PZhhgp2PVOXi0WE3ZD6T8zO+4UmYnVDn1tmfM0Zingp0xN8qAGwrFm5JVlh Fycw== X-Forwarded-Encrypted: i=1; AJvYcCVMj5TNOL/eQ4HrvP3PhkxmwrkRqWy2wjS09xGNo9G/E/Htp3Snb9ajdh/5TL0wnw6g3U/LDecpLYrXXEt+AEiYtE2w8vXJHGWau5Zk3PS3Ne0Yo5o= X-Gm-Message-State: AOJu0YzVVlLiCm/M/xUtE0X1+/cPOYTL5Sx8wkMIWmLOMiRR7eo6VWDG e/4MfgtnVzdYmZEZgjwOsTdZFAq/41KctVX5gC0rlQvTczqm/DgI X-Google-Smtp-Source: AGHT+IF6+iO/0W0LMpOnPmATaN6+Ni/p2mp4ptbLlokGCHrnllKR92jiA0qM4MrXh098DtwZbBN29g== X-Received: by 2002:adf:f584:0:b0:35f:2b1d:433 with SMTP id ffacd0b85a97d-3607a746a11mr9688051f8f.26.1718717451370; Tue, 18 Jun 2024 06:30:51 -0700 (PDT) Received: from localhost (54-240-197-231.amazon.com. [54.240.197.231]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-362907048b0sm671272f8f.24.2024.06.18.06.30.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2024 06:30:50 -0700 (PDT) From: Puranjay Mohan To: Maxwell Bland , "open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)" Cc: Catalin Marinas , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Zi Shen Lim , Mark Rutland , Suzuki K Poulose , Mark Brown , linux-arm-kernel@lists.infradead.org, open list , Josh Poimboeuf Subject: Re: [PATCH bpf-next v7 2/2] arm64/cfi,bpf: Support kCFI + BPF on arm64 In-Reply-To: References: Date: Tue, 18 Jun 2024 13:30:36 +0000 Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240618_063054_405397_8FAA3A1D X-CRM114-Status: GOOD ( 20.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --=-=-= Content-Type: text/plain Hi Maxwell, I am happy to test your code everytime but it would be great if you test the code before posting it on the list. Otherwise it would take multiple revisions for the patches to be accepted. I understand that testing this is non-trivial because you need clang and everything and you also need ARM64 hardware or Qemu setup. But if you enjoy kernel development you will find all this is worth it. > +u32 cfi_get_func_hash(void *func) > +{ > + u32 *hashp = func - cfi_get_offset(); > + return READ_ONCE(*hashp); The above assumes that hashp is always a valid address, and when it is not, it crashes the kernel: Building these patches with clang and with CONFIG_CFI_CLANG=y and then running `sudo ./test_progs -a dummy_st_ops` crashes the kernel like: Internal error: Oops: 0000000096000006 [#1] SMP Modules linked in: bpf_testmod(OE) nls_ascii nls_cp437 aes_ce_blk aes_ce_cipher ghash_ce sha1_ce button sunrpc sch_fq_codel dm_mod dax configfs dmi_sysfs sha2_ce sha256_arm64 CPU: 47 PID: 5746 Comm: test_progs Tainted: G W OE 6.10.0-rc2+ #41 Hardware name: Amazon EC2 c6g.16xlarge/, BIOS 1.0 11/1/2018 pstate: 00400005 (nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : cfi_get_func_hash+0xc/0x1c lr : prepare_trampoline+0xcc/0xf44 sp : ffff80008b1637e0 x29: ffff80008b163810 x28: ffff0003c9e4b0c0 x27: 0000000000000000 x26: 0000000000000010 x25: ffff0003d4ab7000 x24: 0000000000000040 x23: 0000000000000018 x22: 0000000000000037 x21: 0000000000000001 x20: 0000000000000020 x19: ffff80008b163870 x18: 0000000000000000 x17: 00000000ad6b63b6 x16: 00000000ad6b63b6 x15: ffff80008002eed4 x14: ffff80008002eff4 x13: ffff80008b160000 x12: ffff80008b164000 x11: 0000000000000082 x10: 0000000000000010 x9 : ffff80008004b724 x8 : 0000000000000110 x7 : 0000000000000000 x6 : 0000000000000001 x5 : 0000000000000110 x4 : 0000000000000001 x3 : 0000000000000000 x2 : ffff0003d4ab7000 x1 : 000000000000003f x0 : 0000000000000000 Call trace: cfi_get_func_hash+0xc/0x1c arch_bpf_trampoline_size+0xe8/0x158 bpf_struct_ops_prepare_trampoline+0x8 [...] Here is my understanding of the above: We are trying to get the cfi hash from - 4, but clang doesn't emit the cfi hash for all functions, and in case the cfi hash is not emitted, - 4 could be an invalid address or point to something that is not a cfi hash. In my original patch I had: u32 cfi_get_func_hash(void *func) { u32 hash; if (get_kernel_nofault(hash, func - cfi_get_offset())) return 0; return hash; } I think we need to keep the get_kernel_nofault() to fix this issue. cfi_get_func_hash() in arch/x86/kernel/alternative.c also uses get_kernel_nofault() and I think it is there for the same reason. Thanks, Puranjay --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iIsEARYKADMWIQQ3wHGvVs/5bdl78BKwwPkjG3B2nQUCZnGL/RUccHVyYW5qYXkx MkBnbWFpbC5jb20ACgkQsMD5Ixtwdp3AbwD+I2Q0OiLq8foDoUj0DISDhNMGiCcn ZBr+3BwPV151j4YBAPkWjUG3guQHThHmZJjwPVLbhMDHizKBlmgn6sb3qRML =OXLV -----END PGP SIGNATURE----- --=-=-=--