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 760DAC433EF for ; Thu, 21 Apr 2022 19:41:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE0B26B0072; Thu, 21 Apr 2022 15:41:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E90116B0073; Thu, 21 Apr 2022 15:41:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7F0F6B0074; Thu, 21 Apr 2022 15:41:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id C5A8D6B0072 for ; Thu, 21 Apr 2022 15:41:11 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A3F6A26367 for ; Thu, 21 Apr 2022 19:41:11 +0000 (UTC) X-FDA: 79381904742.28.7FAEE33 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id 8539714001C for ; Thu, 21 Apr 2022 19:41:09 +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 E96CE61CC2 for ; Thu, 21 Apr 2022 19:41:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27349C385AD for ; Thu, 21 Apr 2022 19:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650570069; bh=ntFE53p9Qvm/OfNU4+7MbHF6ffpndaoZRWXP15X8/44=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lclm0sJ7SgnvZIpQIxQ07HRxjiwCeNQbVuNvyc3SWJ9gWdk6eaDifmOa1/36XeDKw /EjcwhNYkNMWE5IMBEzQzBYfCHXK6Eln+oH55gIE6/ySAsRagCNrvgB7QIM8FxLTf4 G9GQl1C+neesapvOF3kuCPFk3ywsjoIrUl7xNVq0/lF5T/oc94RHyOQi5aM4Ycky26 wwHh6LsMY84pLENqqZh+MKr38NNjfhxdjPRQOh5UkKXST1HAEl4szsxKMjOXiBajJT mwyamxWCWO4MSxNSERHfXTIyRMcWUtypG9bDi8kl7zgviTkEWeLzAxCQ4uoAMKm46O MWMmcymMJxltg== Received: by mail-yb1-f171.google.com with SMTP id x9so3482187ybe.11 for ; Thu, 21 Apr 2022 12:41:08 -0700 (PDT) X-Gm-Message-State: AOAM531VnIL1VpB+AmxkvgoJGuqMOMVUYpzQSyHG9dcySc7J5GBvrgDh +b2WrVnMVR9v9H/YMpIoNIfdQMV3peQ6QUBlmzU= X-Google-Smtp-Source: ABdhPJwiyImZimNqRZqXCUsmgQavJEPUZ7SAYyM2AhZ42Hk0FpySohvV8lD5LNrh+33hAbGhLLJsR3LnGiQAF6o0Ric= X-Received: by 2002:a05:6902:114c:b0:641:87a7:da90 with SMTP id p12-20020a056902114c00b0064187a7da90mr1356895ybu.561.1650570067256; Thu, 21 Apr 2022 12:41:07 -0700 (PDT) MIME-Version: 1.0 References: <20220421072212.608884-1-song@kernel.org> In-Reply-To: From: Song Liu Date: Thu, 21 Apr 2022 12:40:56 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf] bpf: invalidate unused part of bpf_prog_pack To: Linus Torvalds Cc: Alexei Starovoitov , bpf , Linux-MM , Linux Kernel Mailing List , Alexei Starovoitov , Daniel Borkmann , Kernel Team , Andrew Morton , "Edgecombe, Rick P" , Christoph Hellwig , Andrii Nakryiko Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8539714001C X-Stat-Signature: ywng7tge7wj9hxs677h3y3b3nkduihjq Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lclm0sJ7; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of song@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=song@kernel.org X-HE-Tag: 1650570069-926348 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: Hi Linus, On Thu, Apr 21, 2022 at 11:59 AM Linus Torvalds wrote: > > On Thu, Apr 21, 2022 at 11:24 AM Alexei Starovoitov > wrote: > > > > Let's not complicate the logic by dragging jit_fill_hole > > further into generic allocation. > > I agree that just zeroing the page is probably perfectly fine in > practice on x86, but I'm also not really seeing the "complication" of > just doing things right. > > > The existing bpf_prog_pack code still does memset(0xcc) > > a random range of bytes before and after jit-ed bpf code. > > That is actually wishful thinking, and not based on reality. > > From what I can tell, the end of the jit'ed bpf code is actually the > exception table entries, so we have that data being marked executable. > > Honestly, what is wrong with this trivial patch? This version would fill the memory with illegal instruction when we allocate the bpf_prog_pack. The extra logic I had in the original patch was to erase the memory when a BPF program is freed. In this case, the memory will be returned to the bpf_prog_pack, and stays as RO+X. Actually, I am not quite sure whether we need this logic. If not, we only need the much simpler version. Thanks, Song