Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp819692pxb; Fri, 22 Apr 2022 11:52:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsNrVDg/onF6sOEh82T8aCsvto5KWwoO2Gq/mWhpdn6kzkJt1AmSCPpRKOjrYrOy8i2zM/ X-Received: by 2002:aa7:92c8:0:b0:4fd:c1aa:3e11 with SMTP id k8-20020aa792c8000000b004fdc1aa3e11mr6438759pfa.29.1650653560523; Fri, 22 Apr 2022 11:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650653560; cv=none; d=google.com; s=arc-20160816; b=yo+JBIL7COaf9BP3nA+Od5qk8Qzw9MUF3Rzrm7z1OWzm67DlE7eqiAsqBEDK/ialRc r4idIHN/w24HCw2yCdGhqW9vx9XIzvTeKXEizby0gDcxx368F4EyMeDnzZPB5CKPGBWQ Sj627BA91/f819EfWEk45cBYnSs3klj5QF4zu5TjbGULb+tDJ3qk3Twph9wPDNL20rWs x/P+XP2RFNe6KgUiVyGaBgpdbtt61xKcBYunDNd2+ve5ALL8a9cYGRX+JErscgUze0LT 8cJgi9GqYuozGMS3qvGvQsTkVXJcbNXAMVdyEmNvV0BK7bGIMZ9YOZEZRXia6E2359g8 SvMw== 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=ak9lVWwM+coDmUHY61U+ZihyKQCtIFN8nTMg/HLgunQ=; b=FwyRnE6q67D1Hy3fr9XpDABOc4jWb4mior2z28iLexhTrhjGlnoAchjRsCG9t9lkYS h19weeke3IJjNxzWOwfjHN0p3DswhJosqk0eQfZMVpsC/TOSeUl99Sc2QoVt8ATR+jXj 1OwyRRRN/TtY58DI2cM07m+tpSLfHJWyx8llB9/GuwTopUkGydiuzPMDyV0K51gd1tYW d9Z/VrXBQpMxxcqEuTUGWDGXc2qK664GMbSMskA9vVKS7nFAu1r5oqGXD7qiWTNmPOYN fADJ6EQN7mNXe8cONZTyqSdorreuIaVmCp/Nm3PkeiDZO9Uc9w9Z8Hw/sTNvxSzgMpTU mhVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=dUTQSAcJ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x198-20020a6331cf000000b003aa965fe67csi5426961pgx.611.2022.04.22.11.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 11:52:40 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=dUTQSAcJ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9208E13663B; Fri, 22 Apr 2022 11:17:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391663AbiDUTCU (ORCPT + 99 others); Thu, 21 Apr 2022 15:02:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233912AbiDUTCT (ORCPT ); Thu, 21 Apr 2022 15:02:19 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DEB92194 for ; Thu, 21 Apr 2022 11:59:28 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id d6so10313703lfv.9 for ; Thu, 21 Apr 2022 11:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ak9lVWwM+coDmUHY61U+ZihyKQCtIFN8nTMg/HLgunQ=; b=dUTQSAcJXhEgH56325FZO9cBwpb+y6gnzAUNugFkBCF6CGx9PFgIG3mnV3YjioVs3b TH2pvqbF8RHSX8PsvM64v1T/aseBE32JhDyWgSL5UjmKA/JIDWQwH9YFuRBx6QqXcBTo oZJFMw/LprgNr7LDtNxdhVWuHnyeBLs3xkMBI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ak9lVWwM+coDmUHY61U+ZihyKQCtIFN8nTMg/HLgunQ=; b=AiIw96W72YPPbQd/VhoH6RS0SzsIXEUWYT3cPzQljoBZntjXwfz7iNhUfzkkwj13gX TPE73CZgeqVL5jWUJrzibmJHzX/Te2ZgWYBTiYYDhM4+WqoJvBPjYp5yZ1cQR3dncxsq envb7M8aXr9faz8daxWbg0J3AAttKt2TLBaixVHzXEOkbCsGDb3UDmQAFtPvJYjaNThW dXoDF45q5MkR/qXVRPu1vZ8CeZ8BmfSxZz9sE8vUZ6319/gkF9Q4MnRvrZLc2yQOhdSU c0x81b9G2mUk9ptSP73Zkn7kjaoOcM/EUTOpkM8jayaL3EyAa5JMoVwg9b+vZyh/ld/U MPKA== X-Gm-Message-State: AOAM533NwMMJWnqFkSZVIgeGtTpglydcJ61A9WFqYELelGmh1VupjS7k lavdVUWZYswxxIADqGMr4IkYjHhcYbvUR8LxdF8= X-Received: by 2002:ac2:5923:0:b0:46f:aeef:f269 with SMTP id v3-20020ac25923000000b0046faeeff269mr573124lfi.221.1650567566383; Thu, 21 Apr 2022 11:59:26 -0700 (PDT) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com. [209.85.167.49]) by smtp.gmail.com with ESMTPSA id n4-20020a196f44000000b0047195a0fd47sm1303583lfk.5.2022.04.21.11.59.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Apr 2022 11:59:23 -0700 (PDT) Received: by mail-lf1-f49.google.com with SMTP id x33so10351010lfu.1 for ; Thu, 21 Apr 2022 11:59:22 -0700 (PDT) X-Received: by 2002:a05:6512:3c93:b0:44b:4ba:c334 with SMTP id h19-20020a0565123c9300b0044b04bac334mr582580lfv.27.1650567562684; Thu, 21 Apr 2022 11:59:22 -0700 (PDT) MIME-Version: 1.0 References: <20220421072212.608884-1-song@kernel.org> In-Reply-To: From: Linus Torvalds Date: Thu, 21 Apr 2022 11:59:06 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf] bpf: invalidate unused part of bpf_prog_pack To: Alexei Starovoitov Cc: Song Liu , bpf , Linux-MM , Linux Kernel Mailing List , Alexei Starovoitov , Daniel Borkmann , Kernel Team , Andrew Morton , "Edgecombe, Rick P" , Christoph Hellwig , Andrii Nakryiko Content-Type: multipart/mixed; boundary="0000000000004099a605dd2eb54d" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no 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 --0000000000004099a605dd2eb54d Content-Type: text/plain; charset="UTF-8" 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? I've not *tested* it, but it looks really really simple to me. Take it as a "something like this" rather than anything else. And yes, it would be better if bpf_jit_binary_pack_free did it too, so that you don't have random old JIT'ed code lying around (and possibly still in CPU branch history caches or whatever). And it would be lovely if the exception table entries would be part of another allocation and not marked executable. But I certainly don't see the _downside_ (or complexity) of just doing this, instead of zeroing things. So this is by no means perfect, but it seems at least incrementally _better_ than just zeroing. No? Linus --0000000000004099a605dd2eb54d Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_l29ck8xn0 IGtlcm5lbC9icGYvY29yZS5jIHwgMTAgKysrKysrLS0tLQogMSBmaWxlIGNoYW5nZWQsIDYgaW5z ZXJ0aW9ucygrKSwgNCBkZWxldGlvbnMoLSkKCmRpZmYgLS1naXQgYS9rZXJuZWwvYnBmL2NvcmUu YyBiL2tlcm5lbC9icGYvY29yZS5jCmluZGV4IDEzZTlkYmVlZWRmMy4uYTRjZmMzNTNhNTJkIDEw MDY0NAotLS0gYS9rZXJuZWwvYnBmL2NvcmUuYworKysgYi9rZXJuZWwvYnBmL2NvcmUuYwpAQCAt ODczLDcgKzg3Myw3IEBAIHN0YXRpYyBzaXplX3Qgc2VsZWN0X2JwZl9wcm9nX3BhY2tfc2l6ZSh2 b2lkKQogCXJldHVybiBzaXplOwogfQogCi1zdGF0aWMgc3RydWN0IGJwZl9wcm9nX3BhY2sgKmFs bG9jX25ld19wYWNrKHZvaWQpCitzdGF0aWMgc3RydWN0IGJwZl9wcm9nX3BhY2sgKmFsbG9jX25l d19wYWNrKGJwZl9qaXRfZmlsbF9ob2xlX3QgYnBmX2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