Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp14966ybm; Tue, 26 May 2020 09:35:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdpZd9+2OLdttDx2nD11FfTPotaFVd/rrqnTdPrQYtpu5Yc8z7i7nkwuvcCRO+LWUc3UF4 X-Received: by 2002:a05:6402:1849:: with SMTP id v9mr21153382edy.178.1590510952761; Tue, 26 May 2020 09:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590510952; cv=none; d=google.com; s=arc-20160816; b=QU2u1MHZ2Nil+o8KbFqzC7e3YEHde8UanlNGJNqfNtTEZKFeQ/dvnLlH4iJLyUcEmg c6551n6RGl4cFIHjW+fgxQGMQSAhWLjijc7iJF/oUeOERczMj/NbzkBiMpxXkPohvCv9 yKKE22mnVohikvy7aL9Wj06JRPnfsnK5exjQ3Nvr+JoW9If9bpSOypvN3PlAVNjGbW4+ 9lJTg2E1lpz5h+39IkXSEJ8BIrSTSzTnO4mhUKhYU1Efd0lVL5+7IE0D+ZnKMh7wmvaj pjUME55aGow91lw4ZqG85cOiw73gkEPO2Wqcb1sDvFGKSmarZ+N8GL6V+aMCjAMK+pse 1waw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3d51jgWtfOexQMR16pUfp1Ft+cFFsdNIgNCbJ0oO6z8=; b=Ml0EGlJn9teAtzj9h9GhtoG1YCrbHprufY/nGYFZgtD2GbLJkVbBiMnGRnG9pbacWM gkTXiNobeC1JoabDHx7c6lfOBYrqIux9fgdgOd/J4IpmdAFbbPPP07+BVam8qLJb3ZwA MuJJ69N0l2bUzUCLvIZjuYo96oW1veypq2f1dNUE3u9mJikq1hdxAfGnaHBHsl3JXn1B E6nMxm5VTMjuRgueNDyCg3LzdK8ImOHw9bICm3lsWD3IawyRMqN0/E18ZP8YkEEAIOsS fx7OjrKLiuCiBYkJwZ366XXg0t32IbObfZi/x8dACcvTRglzl4beUJW2koz9MxajfKre wNTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S1vl8LNQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si181909ejc.681.2020.05.26.09.35.28; Tue, 26 May 2020 09:35:52 -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; dkim=pass header.i=@chromium.org header.s=google header.b=S1vl8LNQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728350AbgEZQdl (ORCPT + 99 others); Tue, 26 May 2020 12:33:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727941AbgEZQdk (ORCPT ); Tue, 26 May 2020 12:33:40 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F1E4C03E96E for ; Tue, 26 May 2020 09:33:40 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id q11so8901099wrp.3 for ; Tue, 26 May 2020 09:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3d51jgWtfOexQMR16pUfp1Ft+cFFsdNIgNCbJ0oO6z8=; b=S1vl8LNQNGh9Z9oQEIaEr3gX4dBzKdAj9yZBl9C8Z9eB9PxSDAHYk+yztCPZT/cc5o EiTXiXfHkY+NQVCYy4gS0Vd+ufYrK/Nqn88WnMiNYw8VNbr//5v5JAfanWXjVaa4UPa/ IXmxKiSMm+hlWLN126CkuJ2x4CDQDobvrDzb8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3d51jgWtfOexQMR16pUfp1Ft+cFFsdNIgNCbJ0oO6z8=; b=eLwNSVpi0n8PAEMvh7EVYZh2Ph3gspwPAk/qpEIR79SzT7+wPXbn9/fS/3UA2QaTu4 mvHnos+hFJr/wNsX7hMv4xru+xZK4IWAU/LiV+0pC7W5ud5sXA4bwmh3Do4TY4lnrLDp FBhfK53lnRg8zB7qce8qVoMB8R1itsxiSFKO9a8pZYPvfFY3nRLC/XxCyE/fs0C3Ix77 VN9OeXYiPopLlIA/zsI04SMoyWGddImMstDhHs6m7TyoDhESiOeBql8ZrnS6H/wtjzF8 SaphVLAotm0SzUPJucTDx0OnRkQDefqZ4SWD1qZ70/di400NbY67s2FbVPQU2FIJnw/9 Ehuw== X-Gm-Message-State: AOAM5333QShwDpIymbu7k2yeiOzmiIybeLb5PmlJK72ZDwXX5Qybd7W1 q2Mc2Lg1nvdsCFL5i/Fc2HR+XV/BObc= X-Received: by 2002:a05:6000:110b:: with SMTP id z11mr22098919wrw.16.1590510818551; Tue, 26 May 2020 09:33:38 -0700 (PDT) Received: from kpsingh.zrh.corp.google.com ([81.6.44.51]) by smtp.gmail.com with ESMTPSA id k17sm48654wmj.15.2020.05.26.09.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 09:33:37 -0700 (PDT) From: KP Singh To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , James Morris , Alexander Viro , Martin KaFai Lau , Florent Revest Subject: [PATCH bpf-next 0/4] Generalizing bpf_local_storage Date: Tue, 26 May 2020 18:33:32 +0200 Message-Id: <20200526163336.63653-1-kpsingh@chromium.org> X-Mailer: git-send-email 2.27.0.rc0.183.gde8f92d652-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: KP Singh bpf_sk_storage can already be used by some BPF program types to annotate socket objects. These annotations are managed with the life-cycle of the object (i.e. freed when the object is freed) which makes BPF programs much simpler and less prone to errors and leaks. This patch series: * Generalizes the bpf_sk_storage infrastructure to allow easy implementation of local storage for other objects * Implements local storage for inodes * Makes both bpf_{sk, inode}_storage available to LSM programs. Local storage is safe to use in LSM programs as the attachment sites are limited and the owning object won't be freed, however, this is not the case for tracing. Usage in tracing is expected to follow a white-list based approach similar to the d_path helper (https://lore.kernel.org/bpf/20200506132946.2164578-1-jolsa@kernel.org). Access to local storage would allow LSM programs to implement stateful detections like detecting the unlink of a running executable from the examples shared as a part of the KRSI series https://lore.kernel.org/bpf/20200329004356.27286-1-kpsingh@chromium.org/ and https://github.com/sinkap/linux-krsi/blob/patch/v1/examples/samples/bpf/lsm_detect_exec_unlink.c *** BLURB HERE *** KP Singh (4): bpf: Generalize bpf_sk_storage bpf: Implement bpf_local_storage for inodes bpf: Allow local storage to be used from LSM programs bpf: Add selftests for local_storage fs/inode.c | 3 + .../bpf_local_storage.h} | 14 +- include/linux/bpf_types.h | 1 + include/linux/fs.h | 5 + include/net/sock.h | 4 +- include/uapi/linux/bpf.h | 54 +- kernel/bpf/Makefile | 4 + kernel/bpf/bpf_local_storage.c | 1595 +++++++++++++++++ kernel/bpf/bpf_lsm.c | 20 +- kernel/bpf/cgroup.c | 2 +- kernel/bpf/syscall.c | 3 +- kernel/bpf/verifier.c | 10 + net/bpf/test_run.c | 2 +- net/core/Makefile | 1 - net/core/bpf_sk_storage.c | 1183 ------------ net/core/filter.c | 2 +- net/core/sock.c | 2 +- net/ipv4/bpf_tcp_ca.c | 2 +- net/ipv4/inet_diag.c | 2 +- tools/bpf/bpftool/map.c | 1 + tools/include/uapi/linux/bpf.h | 54 +- tools/lib/bpf/libbpf_probes.c | 5 +- .../bpf/prog_tests/test_local_storage.c | 60 + .../selftests/bpf/progs/local_storage.c | 139 ++ 24 files changed, 1959 insertions(+), 1209 deletions(-) rename include/{net/bpf_sk_storage.h => linux/bpf_local_storage.h} (72%) create mode 100644 kernel/bpf/bpf_local_storage.c delete mode 100644 net/core/bpf_sk_storage.c create mode 100644 tools/testing/selftests/bpf/prog_tests/test_local_storage.c create mode 100644 tools/testing/selftests/bpf/progs/local_storage.c -- 2.27.0.rc0.183.gde8f92d652-goog