Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp126142qtg; Thu, 6 Apr 2023 14:34:04 -0700 (PDT) X-Google-Smtp-Source: AKy350Z1/wUkfa7cU+EUOjC+SQd+zFBSSzrP/qcRcCjc2puniYBB2RHwJr/wop/8Rd/YcCNgA1h6 X-Received: by 2002:a05:6a20:65b:b0:cb:e735:65a5 with SMTP id 27-20020a056a20065b00b000cbe73565a5mr743295pzm.40.1680816844626; Thu, 06 Apr 2023 14:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680816844; cv=none; d=google.com; s=arc-20160816; b=GrJLZSKMh9CYWiunapAsmu2y6etqvMM65DsGmwD/VnmjUy907Avm0M3BXUq+lnh8PG G6MhEcXye24YLlZkt5R9o6wEGdgxpe6G+YC+4i5rwQW5vwDTU7nAJ3SSE6umjjp/wrN/ vDlBuoYfalPj4aKFFty4AeQwqUMsTnvQqDoZqTcK0WU0SZ8loRb/pBcqkjM0a7CG9/lN ZnWSLGyhkKGq/hfucHLmOVb1btgBThNkFA0si0vlgXkasHDc0lcMcws5DWdtCknUjUXT j1Qbxugue4nHsVlpPNo/rlA2Bawi8IRpI4rSoYDB3wmBXyQiku3VO7v7PDDKwjPlBAPc eQFQ== 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=LItukwG4Odlmrx9xSdhd9q03PqIJKqsvFSRXWc9+xyk=; b=Ae/XW/cQ27simwWALJghX/LO1CzsYu2Q0c5BevB61oVcDLUYgaRAtVNaWypox6Tqeu fHbnwgvv0UdLNoIYwuP/3fA2heTXF8ZowSw7TCH2/QfjhsyvqXa/L7eUG+0R2Pr3MqSs kQvXSp7O96tLBK6OEoJW01KgU+iGRbCpeLa0CBl7iOJ3QqYQuSaB+iGQfihMW/P4hmQi FUpvCKjKN8571PfWgNXwt+yR/eX0s2VwOjNOnBlSEFTBrZsymnwWBXpRy7mnQHY4xTXL fdQfw8onXVUQ/R5c4czVZKm3OJ4bfdAsp85wDDeI8VA4Ti7Gm94X/gfZvxkBwfqSelVZ 8gvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=UM94zSWJ; 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=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a63ce47000000b0051418f764b4si2011954pgi.293.2023.04.06.14.33.26; Thu, 06 Apr 2023 14:34:04 -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=@paul-moore.com header.s=google header.b=UM94zSWJ; 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=NONE dis=NONE) header.from=paul-moore.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231411AbjDFVa4 (ORCPT + 99 others); Thu, 6 Apr 2023 17:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231517AbjDFVay (ORCPT ); Thu, 6 Apr 2023 17:30:54 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B13D76592 for ; Thu, 6 Apr 2023 14:30:53 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5416698e889so764561057b3.2 for ; Thu, 06 Apr 2023 14:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1680816653; x=1683408653; 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=LItukwG4Odlmrx9xSdhd9q03PqIJKqsvFSRXWc9+xyk=; b=UM94zSWJxUtUQNyhE2S5+ZnZoISkomXa5IEM3sbIOBFEzGWFdq4izGSbTieIwqRi4F tqtzdxT8yuV5Twubnt0ECfWuAiNzp7DxEtg+wdUKtFwfLivl9I+9BuMFWyvVwLLRfuMq 57aQWmp3QRklpwLsbjs5rSyKvE0ulygpLaMxYhkZlxuoMZIdWLsa0XnN5+ybHHFzVyYW tgbULRp9y5b0j7LUJBdiHqACYk7UOL7D81TF35pfA3UFbpDUNCKQ6p8Vd3qdLVW2d0l+ HfjnbzNro25iv0tnqsx1sddYnyoFvRfrCGOR3LuGZ5d1MiB8gP/L5GK9sdE7K+30fZg0 4tlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680816653; x=1683408653; 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=LItukwG4Odlmrx9xSdhd9q03PqIJKqsvFSRXWc9+xyk=; b=1QG0nUD54RxoSsWfFFL1JlZxcYVAiPsl9Fk7GMfcBBZ2IYzwywQf0mglBfB3LR9xZF 3Qpngqna3iWRQf8B+UOrAtCWnkbj8Ek0n9Eaw0VyaxXdNXyfhfyuzqvPmpuWIp2Ia/E2 ctbtnAAZ9LUtd78QsPvHNqtxK2F2BlrdG27yDBBJz93h5omUM8xo/uX3IKJMPiFByh20 oo6QS/Mxmh5vpF0Ky5M+WRyarVt+D1qebSWx/4RCCSjkE6HSVRou5HjwhHcLPsVLHSOK xQfByJMh+F3kPnZIPGuQfG2IBG+pvGO0V6+CMyNl9EMhzOuOTTmOc/WMJHfBGDNMc9ln p8nQ== X-Gm-Message-State: AAQBX9fIFPqfPz5R+TiunPbG1mZl7eX4pRvlHJdFUVPNBewK8kpHilz0 CVPilR88D/n56PwraRf2EvP/fV/dkusi3uEWRmKt X-Received: by 2002:a81:a94a:0:b0:545:6132:e75f with SMTP id g71-20020a81a94a000000b005456132e75fmr6691505ywh.8.1680816652795; Thu, 06 Apr 2023 14:30:52 -0700 (PDT) MIME-Version: 1.0 References: <0746dd23-5dcf-e858-e15b-159673266f2f@oracle.com> In-Reply-To: <0746dd23-5dcf-e858-e15b-159673266f2f@oracle.com> From: Paul Moore Date: Thu, 6 Apr 2023 17:30:41 -0400 Message-ID: Subject: Re: Semantics of blktrace with lockdown (integrity) enabled kernel. To: Junxiao Bi Cc: Konrad Rzeszutek Wilk , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, jmorris@namei.org, serge@hallyn.com, nathanl@linux.ibm.com, joe.jin@oracle.com, Eric , Boris Ostrovsky , axboe@kernel.dk 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,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, Apr 6, 2023 at 3:30=E2=80=AFPM Junxiao Bi w= rote: > On 4/6/23 11:39 AM, Paul Moore wrote: > > On Thu, Apr 6, 2023 at 1:38=E2=80=AFPM Konrad Rzeszutek Wilk > > wrote: > >> Hey Jens, Paul, James, Nathan, > >> > >> We are trying to use blktrace with a kernel that has lockdown enabled = and find that it cannot run. > >> > >> Specifically the issue is that we are trying to do is pretty simple: > >> > >> strace -f blktrace -d /dev/sda -w 60 > >> > >> [pid 148882] <... mprotect resumed>) =3D 0 > >> [pid 148881] openat(AT_FDCWD, "/sys/kernel/debug/block/sda/trace0", O_= RDONLY|O_NONBLOCK > >> [pid 148882] sched_setaffinity(0, 8, [1]) =3D 0 > >> [pid 148881] <... openat resumed>) =3D -1 EPERM (Operation not pe= rmitted) > >> > >> which fails. The analysis from Eric (CCed) is that > >> > >> All debugfs entries do not exist until blktrace is run. It is opening > >> /sys/kernel/debug/block/sda/trace0 which isn=E2=80=99t there normally.= While running the utility, > >> to place something in it, it must have the write permission set. When= exiting out of > >> blktrace, the entry is gone, both on a machine running with secure boo= t enabled > >> and one with it disabled. Which also indicates the write permission w= as set, > >> otherwise the entry would still be there. > >> > >> The fix is simple enough (see attachment) but we are not sure about th= e semantics of what > >> lockdown has in mind. > >> > >> Looking at the include/linux/security.h the LOCKDOWN_TRACEFS exists wh= ich would > >> imply that it is expected that operations with tracefs *should* work w= ith lockdown (integrity mode). > >> > >> But at the same point, debugfs writable attributes are a nono with loc= kdown. > >> > >> So what is the right way forward? > > What did you use as a basis for your changes? I'm looking at the > > patch you sent and it appears to be making a change to a > > debugfs_lockdown_whitelisted() function defined in > > fs/debugfs/internal.h which does not exist in Linus' tree. If I > > search through all of the archives on lore.kernel.org the only hit I > > get is your email, so it seems doubtful it is in a subsystem tree > > which hasn't made its way to Linus yet. > > > > Before we go any further, can you please verify that your issue is > > reproducible on a supported, upstream tree (preferably Linus')? > > The patch attached is applied to oracle kernel which is just used to > demo the idea of a possible fix. > > Upstream will have the same issue because blktrace uses relay files from > debugfs to transfer trace information from kernel to userspace ... For future reference, the problem with sending patches that aren't based on an upstream tree is that it both wastes reviewer time trying to figure out where the basis of the patch, and it makes one question if the issue is present in an upstream kernel or if there is some out-of-tree patch in the unknown kernel which is the root cause. Maybe you've tested everything and know it is a problem with the upstream code, but when we see a patch that doesn't match up with anything, how are we supposed to know? --=20 paul-moore.com