Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2504238rdb; Wed, 21 Feb 2024 09:31:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX79a/jTLNFoo2gh8JR3wayXXb3bxPFfQ67LSlcAfJwGAOiJRlOzCxvQFeiTcGnDgwGcMo1ul1W8eM1vj0+meCcaiWe5VWFhs1zcSJjUA== X-Google-Smtp-Source: AGHT+IH6Jpcc7eN//SHMMIOkWcOv4fdps8Cn5BKBezvULYDizNp8qPcKBZBYBUyiP5ug37Ap6oxy X-Received: by 2002:a05:6a21:3102:b0:1a0:cc37:f850 with SMTP id yz2-20020a056a21310200b001a0cc37f850mr1400028pzb.36.1708536662095; Wed, 21 Feb 2024 09:31:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708536662; cv=pass; d=google.com; s=arc-20160816; b=qtdufR88Ql6r6SWBQQRHIfbW1zv3gif1WNWqWKZd3DVS08ctlHghz0aAxkA6mdvtep FtVoZLNDGozlfbyCbNWm4pq3UiMpBqtzwUQeGAo4n4Adu68jmFz3rIui6pu5go2fCIy2 je9MYNNmm7SmvD99oB8bfH9kG3gNry3MG/Lp3z2E3wXkcTQz4ql6cLCveTVBiw9oTrWn ZKh0ULelQKS9J/Bs5KJgQ/Vg8Mj9sIaRNHjoGkKgSq9zKIQwx5v/m9garmzZKgH4prm5 V+7s2xhjgVuot9aW6NR0/I/9dXWpcYfB4HVUCffVI+c6/LF8ZBvTGBZ/WoXzYKsm2wQ2 l4LQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=I87YIZpurdfl8CTcBVVyeB1j4NeBVQcdCIaP0A3iopg=; fh=ArTAmdtS0uHpZ9xXixFXYV5vUUB+8Q9sQtFGHrz1IoM=; b=dVTD0PcHTsSWBvq+tYHKd4NhQ9O+pzEg3J2H/78dNIB7QsdhUIT1u4WtDIjuAae+pK rzE38zzTSV6JyOH6wmSH4ZwTKB4SLL2BBMYyF8M5ABHTrDNUqW2ctdONXKNGBk+snlRx vTQFecI4BmWS2Xw/dYvAT5GTpwrElLOVaxMyhmru5RYfbzF8+uF5wyQzeFribZj2mm5t L97cjBAr4GwgqQ0LBM1OCR/OLBjjD7fcjluD2xZR6BcQR8TQcG7PYnUpc4K1FPkaVi8b AKd3ob7/FXDDg9XWOzG921AIkwA7ZYm63oZgxev4ZiqwoTtZ5Wpg5mWxrRRSK4p29K1r qLqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@iogearbox.net header.s=default2302 header.b=Wbi6jkdu; arc=pass (i=1 spf=pass spfdomain=iogearbox.net dkim=pass dkdomain=iogearbox.net dmarc=pass fromdomain=iogearbox.net); spf=pass (google.com: domain of linux-kernel+bounces-75200-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=iogearbox.net Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w30-20020a63935e000000b005dc816e3080si8854037pgm.12.2024.02.21.09.31.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 09:31:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75200-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@iogearbox.net header.s=default2302 header.b=Wbi6jkdu; arc=pass (i=1 spf=pass spfdomain=iogearbox.net dkim=pass dkdomain=iogearbox.net dmarc=pass fromdomain=iogearbox.net); spf=pass (google.com: domain of linux-kernel+bounces-75200-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=iogearbox.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 27937284045 for ; Wed, 21 Feb 2024 17:31:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6FC983CDD; Wed, 21 Feb 2024 17:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iogearbox.net header.i=@iogearbox.net header.b="Wbi6jkdu" Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA53182D8F; Wed, 21 Feb 2024 17:30:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.133.104.62 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708536644; cv=none; b=g8LuG/gwI0UnIy0ilNShZucZOzd53i864m5apw6Iwm1kmUAalgWUoscs91wZTDXzzgI4UOVZ3eaHjC6cJasNRRRqet+iNh4UgGTCUMaiBMZ+v4Dgdje6YCkrp5hrtPo1bpELVUbhYNmXXTzefIWyjN8Vi78Zu+nqhZbhe6TBMbU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708536644; c=relaxed/simple; bh=VVJKBus/4hY3nazwz3pZiLEtUFESTJ1fNiTVxhfAPy8=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=fM4QWwqusHPWuR64guH1A3efrUEKvGoTV2hf6QwWhtIbxyKJHSPtHI05wGN/01WX9XHMqAW3TMUZb2G7/YuSUCq7YBaJuDq1fKeXXX3cBVKaGrWc4zqaNoOM36K7kw/Yf0I5dnPBBKypgX/rwJDMwALkOVQAqThqrS5eQX/mM38= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iogearbox.net; spf=pass smtp.mailfrom=iogearbox.net; dkim=pass (2048-bit key) header.d=iogearbox.net header.i=@iogearbox.net header.b=Wbi6jkdu; arc=none smtp.client-ip=213.133.104.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iogearbox.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iogearbox.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=iogearbox.net; s=default2302; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=I87YIZpurdfl8CTcBVVyeB1j4NeBVQcdCIaP0A3iopg=; b=Wbi6jkduFDxsAg3gq98PHpUcSq aPM+WXH/eyj6E6cMlenpE90+cdly1BVWqZB6ONVaiY8julWfqqoG3pUFl+AvtS7xqybQALkdyiCOo CrpduV0kwBnHP7w1Gvgch5neon/t/NXjK/tlNZVS07pUouiNswnCxjD9E1yMqrgCouzrEvUQrPdPC PvmbhlVxxThM7yvKKISOPzDuh4Z7w3ewE/LNdN/HqMkOSRwqdey/VluqZaJhG70tBSln8j4TL4IKe J8K250ppqDuGsZv87Q1bPknz68dtbZaAutZ01j6/Cxg/QAuaRWMs3tl9BP+p1AMPgMLRbm2StSITl Fns2ykmw==; Received: from sslproxy01.your-server.de ([78.46.139.224]) by www62.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcqQU-000DLL-Kx; Wed, 21 Feb 2024 18:30:34 +0100 Received: from [178.197.249.13] (helo=linux.home) by sslproxy01.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rcqQT-003ehV-20; Wed, 21 Feb 2024 18:30:33 +0100 Subject: Re: [PATCH bpf-next 1/2] bpf: Take return from set_memory_ro() into account with bpf_prog_lock_ro() To: Christophe Leroy , Hengqi Chen Cc: Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "bpf@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , Kees Cook , "linux-hardening @ vger . kernel . org" References: <135feeafe6fe8d412e90865622e9601403c42be5.1708253445.git.christophe.leroy@csgroup.eu> <4d53e0f9-cfee-4877-8b56-9f258c8325f6@csgroup.eu> From: Daniel Borkmann Message-ID: <2abc14fc-a19e-8205-c54f-a87c11ebd5be@iogearbox.net> Date: Wed, 21 Feb 2024 18:30:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <4d53e0f9-cfee-4877-8b56-9f258c8325f6@csgroup.eu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.10/27192/Wed Feb 21 10:23:23 2024) On 2/19/24 7:39 AM, Christophe Leroy wrote: > > > Le 19/02/2024 à 02:40, Hengqi Chen a écrit : >> [Vous ne recevez pas souvent de courriers de hengqi.chen@gmail.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] >> >> Hello Christophe, >> >> On Sun, Feb 18, 2024 at 6:55 PM Christophe Leroy >> wrote: >>> >>> set_memory_ro() can fail, leaving memory unprotected. >>> >>> Check its return and take it into account as an error. >>> >> >> I don't see a cover letter for this series, could you describe how >> set_memory_ro() could fail. >> (Most callsites of set_memory_ro() didn't check the return values) > > Yeah, there is no cover letter because as explained in patch 2 the two > patches are autonomous. The only reason why I sent it as a series is > because the patches both modify include/linux/filter.h in two places > that are too close to each other. > > I should have added a link to https://github.com/KSPP/linux/issues/7 > See that link for detailed explanation. > > If we take powerpc as an exemple, set_memory_ro() is a frontend to > change_memory_attr(). When you look at change_memory_attr() you see it > can return -EINVAL in two cases. Then it calls > apply_to_existing_page_range(). When you go down the road you see you > can get -EINVAL or -ENOMEM from that function or its callees. By that logic, don't you have the same issue when undoing all of this? E.g. take arch_protect_bpf_trampoline() / arch_unprotect_bpf_trampoline() which is not covered in here, but what happens if you set it first to ro and later the setting back to rw fails? How would the error path there look like? It's something you cannot recover. Thanks, Daniel