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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6461FC433FE for ; Wed, 2 Nov 2022 04:05:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB8F36B0071; Wed, 2 Nov 2022 00:05:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C68756B0072; Wed, 2 Nov 2022 00:05:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B30026B0073; Wed, 2 Nov 2022 00:05:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9E6B16B0071 for ; Wed, 2 Nov 2022 00:05:46 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6C63912016F for ; Wed, 2 Nov 2022 04:05:46 +0000 (UTC) X-FDA: 80087163492.18.357F0EB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id F0AFE1A0006 for ; Wed, 2 Nov 2022 04:05:45 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D9329617DA; Wed, 2 Nov 2022 04:05:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92E26C433C1; Wed, 2 Nov 2022 04:05:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667361944; bh=zilE+0RPH4nsjm2cmooo/wxfBWawFsnYOnsjqA7FRNk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=eXzxB4AFqOshlaCSpr8zLi4B4oS8dxpACsfxpI4no0CyRCqguxDgD3L+sGGoXHlcM 7MKaVB0PQD9n9jeXh3W+Te+jFN6vQmKx1biVmtNhkBZYVC/qu6l0VZaWsOMN5YPDph XfTBmq5aBgr/6ABeWRXgYiL4+K7VQsrDrWTRZGC/Rw+DKjc4NVlR7vaxEIaASByMtM xadYLIccjt/VBJXErJTLQXLiRqUIPAkY99ArR1S/lhi2oDaQhYNMISibADY4Xv5b0K WJ48e7rxTYEufCNjbD9k8QUGUnJmMGZ3evh6CMm7uvS4QeQmA9TNpH7dP6KkcNB1Vp rmLoLqjqk5IyQ== Date: Tue, 1 Nov 2022 21:05:42 -0700 From: Jakub Kicinski To: zhongbaisong Cc: Daniel Borkmann , , , , , , , , , , , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Linux MM , , Kees Cook Subject: Re: [PATCH -next] bpf, test_run: fix alignment problem in bpf_prog_test_run_skb() Message-ID: <20221101210542.724e3442@kernel.org> In-Reply-To: References: <20221101040440.3637007-1-zhongbaisong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eXzxB4AF; spf=pass (imf19.hostedemail.com: domain of kuba@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kuba@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667361946; a=rsa-sha256; cv=none; b=cfRH4+Es+mYIkvVvvoW9w2kxD7FjytAZRbtk/eiTBqEbyKdEW05foh/ule2vMNLz9h6CL0 f2XWwqiBYcx0tXzymL5XJ8zMFMpNWZAESZgLP/eSYuWF+B0doPMfx5xoHOR0q/8ciGqenu datXsxLQ6IEdR2OJuleCKyOLhPSZNdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667361946; h=from:from:sender: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rp5I1boLJZbL3hHmHV8f15Kx1AVUlLHCu0J3tBWn6bE=; b=6UEBUPtudziAWQTfyVqreaAM8tmHMZI7dgiSW0Si9NOyAhPPprxk0wPcRSa5trrKjt2NNj KSwUtNUPbbtZ0ySJfCR49cY8rNasJp7495atLJP8BClNDL9ekoM9BC0eaQaSCerq5wZGPZ RheK1RnXyQN1EaNOEAuQTbAolcv9zF0= X-Stat-Signature: r8hrz1zajran1pnzq8u86qu35ktsb7ds X-Rspamd-Queue-Id: F0AFE1A0006 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eXzxB4AF; spf=pass (imf19.hostedemail.com: domain of kuba@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kuba@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam03 X-Rspam-User: X-HE-Tag: 1667361945-965857 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, 2 Nov 2022 10:59:44 +0800 zhongbaisong wrote: > On 2022/11/2 0:45, Daniel Borkmann wrote: > > [ +kfence folks ] =20 >=20 > + cc: Alexander Potapenko, Marco Elver, Dmitry Vyukov >=20 > Do you have any suggestions about this problem? + Kees who has been sending similar patches for drivers > > On 11/1/22 5:04 AM, Baisong Zhong wrote: =20 > >> Recently, we got a syzkaller problem because of aarch64 > >> alignment fault if KFENCE enabled. > >> > >> When the size from user bpf program is an odd number, like > >> 399, 407, etc, it will cause skb shard info's alignment access, > >> as seen below: > >> > >> BUG: KFENCE: use-after-free read in __skb_clone+0x23c/0x2a0=20 > >> net/core/skbuff.c:1032 > >> > >> Use-after-free read at 0xffff6254fffac077 (in kfence-#213): > >> =C2=A0 __lse_atomic_add arch/arm64/include/asm/atomic_lse.h:26 [inline] > >> =C2=A0 arch_atomic_add arch/arm64/include/asm/atomic.h:28 [inline] > >> =C2=A0 arch_atomic_inc include/linux/atomic-arch-fallback.h:270 [inlin= e] > >> =C2=A0 atomic_inc include/asm-generic/atomic-instrumented.h:241 [inlin= e] > >> =C2=A0 __skb_clone+0x23c/0x2a0 net/core/skbuff.c:1032 > >> =C2=A0 skb_clone+0xf4/0x214 net/core/skbuff.c:1481 > >> =C2=A0 ____bpf_clone_redirect net/core/filter.c:2433 [inline] > >> =C2=A0 bpf_clone_redirect+0x78/0x1c0 net/core/filter.c:2420 > >> =C2=A0 bpf_prog_d3839dd9068ceb51+0x80/0x330 > >> =C2=A0 bpf_dispatcher_nop_func include/linux/bpf.h:728 [inline] > >> =C2=A0 bpf_test_run+0x3c0/0x6c0 net/bpf/test_run.c:53 > >> =C2=A0 bpf_prog_test_run_skb+0x638/0xa7c net/bpf/test_run.c:594 > >> =C2=A0 bpf_prog_test_run kernel/bpf/syscall.c:3148 [inline] > >> =C2=A0 __do_sys_bpf kernel/bpf/syscall.c:4441 [inline] > >> =C2=A0 __se_sys_bpf+0xad0/0x1634 kernel/bpf/syscall.c:4381 > >> > >> kfence-#213: 0xffff6254fffac000-0xffff6254fffac196, size=3D407,=20 > >> cache=3Dkmalloc-512 > >> > >> allocated by task 15074 on cpu 0 at 1342.585390s: > >> =C2=A0 kmalloc include/linux/slab.h:568 [inline] > >> =C2=A0 kzalloc include/linux/slab.h:675 [inline] > >> =C2=A0 bpf_test_init.isra.0+0xac/0x290 net/bpf/test_run.c:191 > >> =C2=A0 bpf_prog_test_run_skb+0x11c/0xa7c net/bpf/test_run.c:512 > >> =C2=A0 bpf_prog_test_run kernel/bpf/syscall.c:3148 [inline] > >> =C2=A0 __do_sys_bpf kernel/bpf/syscall.c:4441 [inline] > >> =C2=A0 __se_sys_bpf+0xad0/0x1634 kernel/bpf/syscall.c:4381 > >> =C2=A0 __arm64_sys_bpf+0x50/0x60 kernel/bpf/syscall.c:4381 > >> > >> To fix the problem, we round up allocations with kmalloc_size_roundup() > >> so that build_skb()'s use of kize() is always alignment and no special > >> handling of the memory is needed by KFENCE. > >> > >> Fixes: 1cf1cae963c2 ("bpf: introduce BPF_PROG_TEST_RUN command") > >> Signed-off-by: Baisong Zhong > >> --- > >> =C2=A0 net/bpf/test_run.c | 1 + > >> =C2=A0 1 file changed, 1 insertion(+) > >> > >> diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c > >> index 13d578ce2a09..058b67108873 100644 > >> --- a/net/bpf/test_run.c > >> +++ b/net/bpf/test_run.c > >> @@ -774,6 +774,7 @@ static void *bpf_test_init(const union bpf_attr=20 > >> *kattr, u32 user_size, > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (user_size > size) > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ERR_PTR(= -EMSGSIZE); > >> +=C2=A0=C2=A0=C2=A0 size =3D kmalloc_size_roundup(size); > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 data =3D kzalloc(size + headroom + tail= room, GFP_USER); =20 > >=20 > > The fact that you need to do this roundup on call sites feels broken, n= o? > > Was there some discussion / consensus that now all k*alloc() call sites > > would need to be fixed up? Couldn't this be done transparently in k*all= oc() > > when KFENCE is enabled? I presume there may be lots of other such occas= ions > > in the kernel where similar issue triggers, fixing up all call-sites fe= els > > like ton of churn compared to api-internal, generic fix. > > =20 > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!data) > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ERR_PTR(= -ENOMEM); > >> =20 > >=20 > > Thanks, > > Daniel > > =20 >=20 >=20