Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4318268pxj; Wed, 12 May 2021 03:00:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw86FKFL4xbfaVOu0kCgOgwSfE+z6WKfu8zdbfJF1lg4hHkNJpeE9PMASWh4dXfEdaZYQQO X-Received: by 2002:a50:f40c:: with SMTP id r12mr44399062edm.162.1620813629178; Wed, 12 May 2021 03:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620813629; cv=none; d=google.com; s=arc-20160816; b=whc9bCPQgQQmO9IanNXivKdyKfHQTV9mgwezZ4U8JFC4R7/R2p/raOxXjuxj7Gn7ea PrZZGphrcatcvCO2+SWqrqw0RGiIIv6cCYHLVxmf0duSCtcphTntMmoPtmYHNnfVdjp7 Px4H2TwdzxSXvt7LNI3jbwKI+mBpk+0TzSRyebE4csvOrfNWdA88KqfjhwUKFdyMNLp2 RDV79QxmXDgk4QsCH33hAYsn4JVZ0JnU5io1JAwTxu6J8CbAWBeRho1V49MIpFfh9uyX jfGvHIm3LcFgJE4udHYaYgVx9GblwRq74k4WTkGlteOWnBXQ4A/Q4fnjQx72al8rSJDY mNPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=gNyIG3SBohybBqXtm6l4f4Ev3xUy+l3CN0qAzKrh30w=; b=G5TQ8FwxjHi8iuGXRBSxySiPT0P15cPneHRq+aDaV1qFRaSARBWjDGB35BxTycUCkr 0fGh9Iutmcyfctm0wPuSBz1SkvQ8xoSF7dHho+g8NJghEQ8tzwrORBxwdg0GWMoQvFs2 QZr+PL3WEvO73nuPiDFQ93rchnCPzwVPr3BVzqpRL9tI2GYjPfankEjzIHY1TcgkdcYD YdvdDpT/vZdlV5gSzSgGmHfUORO/dmzHA6l4rf9sFgGt7C1t/gcBg6bD6J+rtp5WJpwh I37J3pBenKtcBG3PSzo6LrbGuXqGpGsGZ5H22+MErqF3YbnPEHdlVe3r/fWlBFABnQKn imLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay17si22251515ejb.496.2021.05.12.03.00.04; Wed, 12 May 2021 03:00:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230182AbhELKAL (ORCPT + 99 others); Wed, 12 May 2021 06:00:11 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:50259 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbhELKAL (ORCPT ); Wed, 12 May 2021 06:00:11 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=yunbo.xufeng@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0UYdyiiS_1620813539; Received: from localhost.localdomain(mailfrom:yunbo.xufeng@linux.alibaba.com fp:SMTPD_---0UYdyiiS_1620813539) by smtp.aliyun-inc.com(127.0.0.1); Wed, 12 May 2021 17:59:00 +0800 From: Xufeng Zhang To: kpsingh@kernel.org, ast@kernel.org, daniel@iogearbox.net, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: revest@chromium.org, jackmanb@chromium.org, yhs@fb.com, songliubraving@fb.com, kafai@fb.com, john.fastabend@gmail.com, joe@cilium.io, quentin@isovalent.com, Xufeng Zhang Subject: [RFC] [PATCH bpf-next 0/1] Implement getting cgroup path bpf helper Date: Wed, 12 May 2021 17:58:22 +0800 Message-Id: <20210512095823.99162-1-yunbo.xufeng@linux.alibaba.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to protect the running application containers by utilizing bpf LSM, we need to upload the security rules into bpf maps in container granularity, however, there is no effective bpf helper to identify the container, especially for cgroup v1. Generally, the only thing which the user side can get is container ID, and the cgroup path for this running container is fixed if we know the container ID, therefore, bpf programs also need to get the cgroup path for the running task in order to apply security rules stored in bpf maps. This patch add a bpf helper - bpf_get_current_cpuset_cgroup_path(), which return the cpuset cgroup path for the current task, since cgroup_path_ns() can sleep, this helper is only allowed for sleepable LSM hooks. Concern: Since cgroup_path_ns() takes 'cgroup_mutex' and 'css_set_lock' lock, I'm not sure if there is any dead lock code path in LSM hooks. Xufeng Zhang (1): bpf: Add a BPF helper for getting the cgroup path of current task --- include/uapi/linux/bpf.h | 13 +++++++++++++ kernel/bpf/bpf_lsm.c | 28 ++++++++++++++++++++++++++++ tools/include/uapi/linux/bpf.h | 13 +++++++++++++ 3 files changed, 54 insertions(+)