Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp100952lqg; Wed, 10 Apr 2024 17:26:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXj9nnzWMkS54mWhnz0wJ3PFaHA2moVd1lbYj4J0bNB98P5KKX4D4uZNaTzZpJ0S/fCRGHaBfDHwneSDWTqtMTmfvb18IZq8xxs2c2umA== X-Google-Smtp-Source: AGHT+IHLyoRvDKwwbpRbVIPiEw7B+cDOjbnRQuNpge6tt3D2hRDDbd4H+WWKSQ1oxMjk3S40/5JL X-Received: by 2002:a05:6808:b22:b0:3c5:ef39:9fd7 with SMTP id t2-20020a0568080b2200b003c5ef399fd7mr4083713oij.34.1712795202115; Wed, 10 Apr 2024 17:26:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712795202; cv=pass; d=google.com; s=arc-20160816; b=031c1kOd29aJCRu2VUKCBwRZM29TXgiyjPgFukElPhWfex/pfQqKkc8Mp5ZI1s4j+f dqwItrRQbhLX89ER0N9D4cVGmWW9v/LUIwtLPZXUQbplIOz+OyxetNE4aJDYHQ7ZD5G4 G3atxM0TgZZfUYimC9CgVfbkB/cRFKUzHNKVgSFmVFDXO07pkxfc+RftT8AclVtyl9c2 SijOWdP7z48jq7RFES0sXS04Pv/ZWaAtnTV5sqiwetemrliiXq6kmd9wA41bCSVxvF1Q Ilqr9KuVmrWUhaIp788kFApKkF50RPWgmVUjtD9CtkIjpSH9Dqbxvl02kqnxfRE/29Ph p4qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=gB2Wp3EMMPBhX4wRoJ9ubR900ORB8tJWdO8CVq4jwWQ=; fh=msnmmjJ9p159oAlRWI/kNEQwmqOXu4D5jTdIlpkGZ9A=; b=PSNoWZrB+CqBvrHFw6rbeeI2n23+LI8RUp4pL4AuELiH7WD+k69EdBt+3slRkGL4Wc bV5fQd6WrkO8E3/u9BCVYkhKT0aoZz0AZ4lRduFkejbQbelmpTlW3wgrpnkJDLb5deOm LG3Gi6AN4761MyLRobUqlxyWH24qzU/13H79IIu4opJp48guT6i5BUqc8clusBwwgnJt IVEpo8OpyJ+5Inqto2FDbk1QVvLI1E7p5lVVdU5zECpmCQLV+XUb5zXlUOCgEjZs3cnv b/sfykVuLpWfm/C2UB0iMNVx7cLX8ZK56SqFCmgjBmE6sQhg3mCAciO9II/1+687VzAF zj/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZPkn0pwI; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-139584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139584-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y15-20020a05622a004f00b00434e8572b00si379037qtw.82.2024.04.10.17.26.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 17:26:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZPkn0pwI; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-139584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139584-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CA6B31C21D31 for ; Thu, 11 Apr 2024 00:26:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 327F7323D; Thu, 11 Apr 2024 00:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ZPkn0pwI" Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 8A8E4A41 for ; Thu, 11 Apr 2024 00:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712795190; cv=none; b=gJwHfDenkOTde1/YNoblAQ4/ZIYIWuxyEpkpAv6ycYOPu6MsSwIHl3S6piJ5ML35dPD2yY4MqwaSuAJaztpffB74HHBIdUxP/TsVW7qnsgOJWJtI0Kw5DI9i4SzsLBuTQAehLeykHWjEpQ0oLuxecf6y5bPY2mNninI/0MxnzVA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712795190; c=relaxed/simple; bh=iOxJT8OfTlI2kJRkaXpBe16OPqSDgaEyZ9Me/w385Wc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dhYsP0eyJzWlqwOWladitnF2XS/YINdTnhzp4pbo6DXo4DPNHKmgz0Ub/xxK9nGcGG/4XnRDwx+L/m4/8qwxSmKLkA00q/o8W56ViFbmn/+g1aW1vU/5rLmNa2iVekj/b5xqjtX4DbyZOLTONF2N4U8txN/Ez256SX/B1+AUMko= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ZPkn0pwI; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <31904afe-1d8a-4169-a3bd-d6d1c86cac5f@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1712795186; h=from:from: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; bh=gB2Wp3EMMPBhX4wRoJ9ubR900ORB8tJWdO8CVq4jwWQ=; b=ZPkn0pwIJRwaHIbkfEkVSdU9ecajbn7zceHnEAJi/o70wwJfHYmj3NZOCeYFMxYXFAXR0C Mb9wM84w4gd8qYC/C4KAzd+Vo8BhaVCZm5Bzs0ueih2vvXuPUsPI8hKxnOnEzZJmb0Y8dt YrFK1drcLrl96FZP67JFf7ejx+FK/0s= Date: Wed, 10 Apr 2024 17:26:18 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [RFC PATCH bpf-next 0/3] bpf: freeze a task cgroup from bpf Content-Language: en-GB To: =?UTF-8?Q?Michal_Koutn=C3=BD?= , Djalal Harouni Cc: Tejun Heo , Zefan Li , Johannes Weiner , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20240327-ccb56fc7a6e80136db80876c@djalal> <20240327225334.58474-1-tixxdz@gmail.com> <705d7180-aced-46ba-80a6-84ac4e2b96b9@gmail.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yonghong Song In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 4/9/24 8:32 AM, Michal Koutný wrote: > Hi. > > On Tue, Apr 02, 2024 at 07:20:45PM +0100, Djalal Harouni wrote: >> Thanks yes, I would expect freeze to behave like signal, and if one >> wants to block immediately there is the LSM override return. The >> selftest attached tries to do exactly that. > Are you refering to this part: > > int BPF_PROG(lsm_freeze_cgroup, int cmd, union bpf_attr *attr, unsigned int size) > ... > ret = bpf_task_freeze_cgroup(task, 1); > if (!ret) { > ret = -EPERM; > /* reset for next call */ > ? > > >> Could be security signals, reading sensitive files or related to any >> operation management, for X reasons this user session should be freezed >> or killed. > What can be done with a frozen cgroup after anything of that happens? > Anything besides killing anyway? > > Killing of an offending process could be caught by its supervisor (like > container runtime or systemd) and propagated accordingly to the whole > cgroup. > >> The kill is an effective defense against fork-bombs as an example. > There are several ways how to prevent fork-bombs in kernel already, it > looks like a contrived example. > >> Today some container/pod operations are performed at bpf level, having >> the freeze and kill available is straightforward to perform this. > It seems to me like an extra step when the same operation can be done from > (the managing) userspace already. > >> For generalizing this, haven't thought about it that much. First use >> case is to try to get freeze and possibly kill support, and use a common >> interface as requested. > BTW, I notice that there is bpf_sys_bpf() helper that allows calling an > arbitrary syscall. Wouldn't that be sufficient for everything? This is not true. Currently, only 'bpf' and 'close' syscalls are supported. static const struct bpf_func_proto * syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { switch (func_id) { case BPF_FUNC_sys_bpf: return !bpf_token_capable(prog->aux->token, CAP_PERFMON) ? NULL : &bpf_sys_bpf_proto; case BPF_FUNC_btf_find_by_name_kind: return &bpf_btf_find_by_name_kind_proto; case BPF_FUNC_sys_close: return &bpf_sys_close_proto; case BPF_FUNC_kallsyms_lookup_name: return &bpf_kallsyms_lookup_name_proto; default: return tracing_prog_func_proto(func_id, prog); } } More syscalls can be added (through kfunc) if there is a use case for that. > > (Based on how I still understand the problem: either you must respond > immediately and then the direct return from LSM is appropriate or timing > is not sensitive but you want act on whole cgroup.) > > Thanks, > Michal