Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp18740rwl; Fri, 24 Mar 2023 19:56:31 -0700 (PDT) X-Google-Smtp-Source: AKy350aVoC8AWBQCxiBDrgozdQBHRljiNmUzj7pnFJwcfh8JwgvJS3kU+s3qS2VQcJdQ4lyZRgmb X-Received: by 2002:a17:902:cf4e:b0:1a2:1922:985b with SMTP id e14-20020a170902cf4e00b001a21922985bmr3538392plg.59.1679712991227; Fri, 24 Mar 2023 19:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679712991; cv=none; d=google.com; s=arc-20160816; b=X8Ps/dtKPxi0e7otQhRwn2a+bk2Yi1hcLNKUpYIg+W82gAyHOp4cY/lwU/XWPvOp3D gWKy+Po3EsB/LOu6LrlS+IqzfHXIAi4HHwdvWBgJxPol3jRhv7pLs2Mufeu3JsRWruHg GEQkWSbCzoQvmGIY40RlwT+s3PAZNR2Dvv9rqT8NA6m3Zdkl7B0hamh48L4FRktVEQsl VniA2MpV2QDyW2MFFqt97KtFzxmxRqKKo4qsFe0yPPUMoXqhGptCeNJJZ7uooVgs1CAJ q+l/9vk/Y7IWzo0hEHScWqbKInYxBWrnTxkjlh+fH6EKgsKsosnhanJuDvu3DEPZLIHi lQRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=sRLA3AVBBHEbXMLoaXv9UfX4+UgIZrAq1UG9X24q8oA=; b=NSoQIiqgIQEu0Xd+JTRhYEJUlAchSz7S68te+J6Vg3UpHkqP8JOSTiFrw7DrIR2k2Y 0ftBafcccF7cCn2S5V+cev91KYQHNKxpXnF/wPm2GqnA2F+jak4PY3UP4K3rAK+6/07Z zmCyPaUYCPbR6awLv2wt0arnel4XqLjCQb1FSKeIhZTo0U+IGD9LvT1YAJlnwb7tQggh iq88qwLRXFEVciNLOMxYMUL/aBiVxcVhloiRdF18nvjQc4fU9Ov7aybhnCBI8zrqexuj 5sqaHOUfiKd/AMoD946yRLN+Gdgykdr+mZBq+1XYlnBKjv0XxGlVyPo+47jPvKmjAcdw HGIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UYqqbQxr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a170902f54200b001a216fddd00si3198856plf.646.2023.03.24.19.56.19; Fri, 24 Mar 2023 19:56:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UYqqbQxr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231508AbjCYCyn (ORCPT + 99 others); Fri, 24 Mar 2023 22:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjCYCym (ORCPT ); Fri, 24 Mar 2023 22:54:42 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C4F215170; Fri, 24 Mar 2023 19:54:40 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id i5so15103146eda.0; Fri, 24 Mar 2023 19:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679712879; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sRLA3AVBBHEbXMLoaXv9UfX4+UgIZrAq1UG9X24q8oA=; b=UYqqbQxrYcFlwyWfoAsiljg848pmpCwLH0hEVNA96BfXUEEAOxU2eOOeNeK4626oeI Y39dn/yp8caxqBtGxdPRJFKnOdGW+OzuxKmglhwUraMBrRCFwkTw6idY1MEhcvvBTSQd 3/O17kP84zwpOg+BRpmtkRCJOAmUZqKOMk1QlYh4LUGCwCKljFh/7EpDeUJfvLTb5lWG 5AM3kIHP0cZX/fHnw7epNnOtRiT22bb13M7azFm1qJWohtDdGQw+PdTNelTPGd37OGrF fooNiMSl/HBfPzLi80EwGpxNINV0XiwaXSgj+Jk4uIFOQhW44T44yX018u+GoDkdQLga NWMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679712879; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sRLA3AVBBHEbXMLoaXv9UfX4+UgIZrAq1UG9X24q8oA=; b=kmlxxQG24eoIC9Sq0VqzRXViaf/5K5L17fhwKVx7C5Ev5faTDEs47witWM4cMo1qJz oAJZfKsHb0kR+8w9e0DCPvbqUZVtFatQwQXeZiiuyRQLE1JaPAlbZ9bPHwGxXy6npgvF 7L9SMm6mrgnTSugNVVP4a5OECxg2MJrQKfom+6Q6Pa+xH7IIGJjtIwa4YCJIdoFO4p7C ZWMVGW+aqSulLaO2yyVemqqLBTaTxTVbp6EnhsPlWrtJGlHRSePBssTpaOY3I2JZwyMH o0ITlB9D+m5yT/Hnsqmt99H9N8edQwhCjw2BQ44/Ite3DtfrYEin7F+dDHHeeU1yt71q d3NA== X-Gm-Message-State: AAQBX9ecWZF2oIfkG7tcNxgBU+7XCkqX4U+Nc7uWdlbQXGO9lXl8gUFA j9N1gSLaAy/R9jkhwrfescsYEjbhsOxWDezBPFQ= X-Received: by 2002:a17:907:da8:b0:877:747d:4a85 with SMTP id go40-20020a1709070da800b00877747d4a85mr2582166ejc.3.1679712878695; Fri, 24 Mar 2023 19:54:38 -0700 (PDT) MIME-Version: 1.0 References: <20230317145240.363908-1-roberto.sassu@huaweicloud.com> In-Reply-To: From: Alexei Starovoitov Date: Fri, 24 Mar 2023 19:54:27 -0700 Message-ID: Subject: Re: [PATCH 0/5] usermode_driver: Add management library and API To: Roberto Sassu Cc: Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Shuah Khan , Christian Brauner , "open list:DOCUMENTATION" , LKML , bpf , Network Development , "open list:KERNEL SELFTEST FRAMEWORK" , "Eric W. Biederman" , "Luis R. Rodriguez" , Roberto Sassu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On Thu, Mar 23, 2023 at 6:37=E2=80=AFAM Roberto Sassu wrote: > > On Wed, 2023-03-22 at 15:27 -0700, Alexei Starovoitov wrote: > > On Wed, Mar 22, 2023 at 5:08=E2=80=AFAM Roberto Sassu > > wrote: > > > On Tue, 2023-03-21 at 19:23 -0700, Alexei Starovoitov wrote: > > > > On Fri, Mar 17, 2023 at 7:53=E2=80=AFAM Roberto Sassu > > > > wrote: > > > > > From: Roberto Sassu > > > > > > > > > > A User Mode Driver (UMD) is a specialization of a User Mode Helpe= r (UMH), > > > > > which runs a user space process from a binary blob, and creates a > > > > > bidirectional pipe, so that the kernel can make a request to that= process, > > > > > and the latter provides its response. It is currently used by bpf= ilter, > > > > > although it does not seem to do any useful work. > > > > > > > > FYI the new home for bpfilter is here: > > > > https://github.com/facebook/bpfilter > > > > > > Thanks. I just ensured that it worked, by doing: > > > > > > getsockopt(fd, SOL_IP, IPT_SO_GET_INFO, &info, &optlen); > > > > > > and accepting IPT_SO_GET_INFO in main.c. > > > > > > > > The problem is, if other users would like to implement a UMD simi= lar to > > > > > bpfilter, they would have to duplicate the code. Instead, make an= UMD > > > > > management library and API from the existing bpfilter and sockopt= code, > > > > > and move it to common kernel code. > > > > > > > > > > Also, define the software architecture and the main components of= the > > > > > library: the UMD Manager, running in the kernel, acting as the fr= ontend > > > > > interface to any user or kernel-originated request; the UMD Loade= r, also > > > > > running in the kernel, responsible to load the UMD Handler; the U= MD > > > > > Handler, running in user space, responsible to handle requests fr= om the UMD > > > > > Manager and to send to it the response. > > > > > > > > That doesn't look like a generic interface for UMD. > > > > > > What would make it more generic? I made the API message format- > > > independent. It has the capability of starting the user space process > > > as required, when there is a communication. > > > > > > > It was a quick hack to get bpfilter off the ground, but certainly > > > > not a generic one. > > > > > > True, it is not generic in the sense that it can accomodate any > > > possible use case. The main goal is to move something that was runnin= g > > > in the kernel to user space, with the same isolation guarantees as if > > > the code was executed in the kernel. > > > > They are not the same guarantees. > > UMD is exactly equivalent to root process running in user space. > > Meaning it can be killed, ptraced, priority inverted, etc > > That is the starting point. > > I suppose you can remove any privilege from the UMD process, it just > needs to read/write from/to a pipe (and in my case to use socket() with > AF_ALG to interact with the Crypto API). > > Also, as I mentioned, you can enforce a very strict seccomp profile, > which forces the UMD process to use a very limited number of system > calls. > > For the interactions of the rest of the system to the UMD process, you > could deny with an LSM all the operations that you mentioned. The rest > of the system would not be affected, only operations which have the UMD > process as target are denied. > > > > > > I have two use cases, but for sake of brevity I will propose one. > > > > > > > > > > I would like to add support for PGP keys and signatures in the ke= rnel, so > > > > > that I can extend secure boot to applications, and allow/deny cod= e > > > > > execution based on the signed file digests included in RPM header= s. > > > > > > > > > > While I proposed a patch set a while ago (based on a previous wor= k of David > > > > > Howells), the main objection was that the PGP packet parser shoul= d not run > > > > > in the kernel. > > > > > > > > > > That makes a perfect example for using a UMD. If the PGP parser i= s moved to > > > > > user space (UMD Handler), and the kernel (UMD Manager) just insta= ntiates > > > > > the key and verifies the signature on already parsed data, this w= ould > > > > > address the concern. > > > > > > > > I don't think PGP parser belongs to UMD either. > > > > Please do it as a normal user space process and define a proper > > > > protocol for communication between kernel and user space. > > > > > > UMD is better in the sense that it establishes a bidirectional pipe > > > between the kernel and the user space process. With that, there is no > > > need to further restrict the access to a sysfs file, for example. > > > > If a simple pipe is good enough then you can have a kernel module > > that creates it and interacts with the user space process. > > Few points I forgot to mention. > > With the UMD approach, the binary blob is embedded in the kernel > module, which means that no external dependencies are needed for > integrity verification. The binary is statically compiled, and the > kernel write-protects it at run-time. > > Second, since DIGLIM would check the integrity of any executable, > including init, the PGP signature verification needs to occur before. > So, the PGP UMD should be already started by then. That is not going to > be a problem, since the binary is copied to a private tmpfs mount. > > > Out-of-tree bpftiler can do that, so can you. > > As far as I can see, the out-of-tree bpfilter works exactly in the same > way as the in-tree counterpart. The binary blob is embedded in the > kernel module. > > > PGP is not suitable for kernel git repo either as kernel code or as UMD= . > > Well, the asymmetric key type can be extended with new parsers, so this > possibility was already taken into account. The objection that the PGP > parser should not run in kernel space is fair, but I think the UMD > approach fully addresses that. > > Also, I agree with you that we should not just take any code and > pretend that it is part of the kernel. However, in this particular > case, the purpose of the PGP UMD would be simply to extract very few > information from the PGP packets. The asymmetric key type and the > signature verification infrastructure already take care of the rest. > > PGP keys and signatures would act as an additional system trust anchor > for verifying critical system data (for DIGLIM, which executables are > allowed to run), similarly to how X.509 certificates are used for > verifying kernel modules. RPM headers, executables digests are taken > from, are signed with PGP, so there is no other way than adding this > functionality. > > And unfortunately, especially for features impacting the entire system, > out-of-tree drivers are not really an option: I think you have to start out of tree and prove that the PGP thing is worth considering at all. Only then we can talk about merits of UMD and generalization of pipe interface if it's applicable. DIGLIM and everything else you mentioned above doesn't add weight to the decision. PGP work should be acceptable on its own. Out-of-tree is a method to prove that it works and later argue for inclusion as in-tree either as kernel module or UMD. Generalization of current bpfilter is out of scope here.