Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp855833pxb; Fri, 22 Apr 2022 12:43:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynhSMvcmieDoVNeZ1KoVBkEH5oFfwVgq/1kmBthLePV+4JjIaFhTzeu8jXHpqB+du30EL2 X-Received: by 2002:a17:902:cf0a:b0:156:39c9:4c44 with SMTP id i10-20020a170902cf0a00b0015639c94c44mr5874188plg.124.1650656609550; Fri, 22 Apr 2022 12:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650656609; cv=none; d=google.com; s=arc-20160816; b=epctwoTWG9l/j94INr9IZOcZZKsMlhffVROeIuKhVXQRkJBeqnvwfyNXsxoHVEok9b nBXJocs90CswDIc4oQRfmoH5XFPsi3M/3MqFhOoC5/fCwF4ZRFEZGU62o6bHYN6iVInF Z66rPOvN7PYDdP16cii0svTl1f6ZWcK/ighW/SzphZG9TdStsFdAQjuqc7LVtEZ+j0f4 ZIPvdv5r0sxW6JO/HDYb1puoFC43FHAhtumup8QpRr5KFcdxbxexSwOGpRzWPuKBC4vM eeSbbwoI6rHaMyfA6kBkPj5yw8CBD7a6C04K3/oQO5Ifej8W8JHIAXG7oJZNg0mE3USq JTNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ntFE53p9Qvm/OfNU4+7MbHF6ffpndaoZRWXP15X8/44=; b=tPJdFnRMBLgER4dYMiLh2Iqz8LdJ46szDyxU+Eo70bYUikpKNrRGKHa6IrDKKxTLi1 Fsp8+Dl/1G0kFY4YvqOj+oLUmv7mIm7LkYw0Fcvrlw3evK9hS9enevzkz+xeFdKGKPKV /5XgdOdqQy7jqJXBSuYWpAmNl8ddnGUMjz9nacyO2EtyWqMwmaAjhSg7zN6BTBUH/wEY 7dmvLkHFyL92ez91BmoGqym++xdUSV1MKXPrbq7UvtdUyVGt5bO9IQee77jmaDyaHoOq YbzpJ8TL0W6S4Uu0upTKEJFE2z/UGGRNpq+n46hdHF2tKybFR8l5jABkyy367lMlYNTK UMCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U6A8w2kI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n13-20020a170903110d00b00153b2d16415si9804456plh.29.2022.04.22.12.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:43:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U6A8w2kI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 09193206C0F; Fri, 22 Apr 2022 11:48:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232891AbiDUToF (ORCPT + 99 others); Thu, 21 Apr 2022 15:44:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232840AbiDUToB (ORCPT ); Thu, 21 Apr 2022 15:44:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAE984B87F; Thu, 21 Apr 2022 12:41:10 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 66FA6B823F3; Thu, 21 Apr 2022 19:41:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A644C385A5; 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=1650570068; bh=ntFE53p9Qvm/OfNU4+7MbHF6ffpndaoZRWXP15X8/44=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=U6A8w2kIaR4rJ1fCtXKRialGvxNMKx7SOP2BThd7NjCisYDwRYtM/EmpLmDc5I1kE y83SO568wSzu51M5vYPxitcCX5rxQiT5ZkS+M8Ux0Dtb6gzy8ZMiOci0uD588JdopU VtcdMmpp9ML+B6fo268mIPOxuUBkiaLqr1u82TdS7ne/pP3grdIvSe+3lbefGZyV02 AhhLePzwv0c+8gL6jFyC2/4XZHdpnN43ZlYjkXv0YFUo4kvpamX4/Ty0WYmHh0MyuW L/rXhPxovhlws+6aax+2fO7BG+r2iuY1NcLNHkiD9GpbdeP0RNR2EYBWnP+Y71js9F 6CsOGmjxTVgDQ== Received: by mail-yb1-f178.google.com with SMTP id b26so4950255ybj.13; Thu, 21 Apr 2022 12:41:08 -0700 (PDT) X-Gm-Message-State: AOAM5334hw/e1llg32ZFu50OCuUXiYwc+QWDGJ08LReu21ySGXukIrpN uzYVvjkC4HLaxx9R1SF9kAPQ6n4i8xeamGADgdw= 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-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 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