From patchwork Wed Apr 12 20:53:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junxiao Bi X-Patchwork-Id: 13209505 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB4DFC77B6C for ; Wed, 12 Apr 2023 20:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbjDLUxj (ORCPT ); Wed, 12 Apr 2023 16:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbjDLUxi (ORCPT ); Wed, 12 Apr 2023 16:53:38 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8DF12737; Wed, 12 Apr 2023 13:53:31 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33CJTWm6007826; Wed, 12 Apr 2023 20:53:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=LVRBXwMkktKNrIJhzmiTuaNht5Oct2+j/Tpu5+GMZCo=; b=1TDLpJZQemr1jtlP+Q4XAqSmGH8BLdluaEv7uV7NCg/lmSOOEGJIh/PEsUoSdM41wYsx JUP/S/KdCPBBpdBp4kfZJFeEYz46RIuZw4ELyweZ3eshDEFsFq3/C5QohEDL76rjyPQs 23kWufp8cvuozruCIEhQHwy2aD/mYkQful5EGGu30xekFdKetmeuvBoPvdyrF9CM/Ffc jGEI/grTs9Lsqdzmcg9cYj+nzl+qQHggaUKBzLko4p5/QBBhuZJ8uyXNxT1vxYpQecH0 wK9yzJgtT+nI75wvGj5A//KulRnFlU1uzaPMBrn5RDc2iqB3DHNP6tnBX8dx517nPsJL kw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0etsa1f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Apr 2023 20:53:24 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33CJk0K5012666; Wed, 12 Apr 2023 20:53:23 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2105.outbound.protection.outlook.com [104.47.58.105]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3pwwgpxegx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Apr 2023 20:53:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OBdapt84zbmy5vqDNWPhHu87SO6vY1eVdTiz8EQ6N58uZqQkHX9P4+JIpWR2Ho97iYvyWo9rjj5cNsC7RwXUKe3WmGuhYO4FeeCcIs9NrHGa0aAyefn2pun+oc8KvqH09Db6akptXe/a01nBt8bUlPfR7+qbeAkHeM00J6uKLUiDuFm85RAJdKWqMWB8u3A8K9+plVOfcybMFAVKtvUd6JSKmVQdy/4GkdBPS+veh/YIpYAKU+Hla/Nc2D3IgIdPeeRMqpHchC0BaTrls2qjVy95O1F1yKTxsl3ug5D8upCHrbQrcGg69t1tN5OkVnI/j1eC9w7S6gzTkAamS50dsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LVRBXwMkktKNrIJhzmiTuaNht5Oct2+j/Tpu5+GMZCo=; b=LmCt14iJ9assmdvWOvVI03CnXKFV7t7scPjVHTpk3T/S9iL+kewWgXS5iQSA/+6A6XK/imWoC5ZPbqpaS9milxvIuo8d3KKluNlTlp5l+66T0psRN14DrIKEyUa3l3vRgtSNXiolUosqqUj2W28lfQu3h8Vh1PpHGPyWEh4GyCANfhALsQAILM36h5BJE3UecZSbOKJiNg73H35C5i53PO3npi9Z7ZDVTVwshVZn7Idm8sJCRgAcxipm0iA22mkQSdjyh08DRPYBHfYImFMZJh3xy3UoJX7YBikyGqWBHAZc9yK/wAB5/y1jGjjk604mKvmUXvHm7lzAtFWZN5IN8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LVRBXwMkktKNrIJhzmiTuaNht5Oct2+j/Tpu5+GMZCo=; b=Oime8J4aqtidLSulUBwSiUMb4YkrryYVxY3+O7ZqqrbR89/dfQwFYwn9Q7XHFK1wSwP580TR6rI6XY27EhvR/SUfx588AUfQqOEk6zWsiBumbwJ/8ssLJ42iJyjaEWR+KZiNU4u0+aw7BlOHLNx8soFzW4s2bfWrHaMpS2rAtvk= Received: from SJ0PR10MB4752.namprd10.prod.outlook.com (2603:10b6:a03:2d7::19) by PH0PR10MB5548.namprd10.prod.outlook.com (2603:10b6:510:db::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.36; Wed, 12 Apr 2023 20:53:20 +0000 Received: from SJ0PR10MB4752.namprd10.prod.outlook.com ([fe80::b3a1:e02e:37d0:afa1]) by SJ0PR10MB4752.namprd10.prod.outlook.com ([fe80::b3a1:e02e:37d0:afa1%8]) with mapi id 15.20.6277.035; Wed, 12 Apr 2023 20:53:20 +0000 From: Junxiao Bi To: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, nathanl@linux.ibm.com, axboe@kernel.dk, konrad.wilk@oracle.com, joe.jin@oracle.com, junxiao.bi@oracle.com Subject: [PATCH V2] debugfs: allow access relay files in lockdown mode Date: Wed, 12 Apr 2023 13:53:16 -0700 Message-Id: <20230412205316.7114-1-junxiao.bi@oracle.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) X-ClientProxiedBy: SN6PR16CA0061.namprd16.prod.outlook.com (2603:10b6:805:ca::38) To SJ0PR10MB4752.namprd10.prod.outlook.com (2603:10b6:a03:2d7::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB4752:EE_|PH0PR10MB5548:EE_ X-MS-Office365-Filtering-Correlation-Id: c104e925-ed26-49db-f007-08db3b97f2c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qyB/EvgWDgn9DKtdJaSGuCD+VtxSI/SQsycgi0IVXieWo2gkXud4WkAvL6ZrFneloUsC7f59kSnJaDmNvBmewp3mDVN9QPnA54mPzSS6AfTrpzx8j9M1OzPLIULCKa4aNJ21pV+10XbKXBE2feW08Wg7BIc7t6qocylt3H1CTOU5SNTXOoR8Cxlbb0aWyZR8ivFCKSHfg0RQ5h0GHVtmirap7tUI+Iv1VNNMTpo/pnvlIQ4Ey5O/AookFYmll+Zrrd7kzZUcy5VHBOkhb04rWYmzIYkAt+1F5CVxFAI22oia3VSHNf6WJiWfySyeN0Dq4uuYcjuNUIqlli6VAUFS5zJ24CmpY/FXZqWikwbD5R4EdiPIzTxpYdvZ3t9jAWDC12ihjpdk9PRd413ssvSASn5ZUYNYBX98PXg4jYGQK1EhnWC07qqS0DDAPVSllsr+GqGvIX2wRTgdDUoeMfpDZ3SK0eMpdjg09GbsCmruVjwHKIgVgguQyBAuboX0cl4MGYPMqdIF15xljP/1ErNHaoYJ0jEljD2SjGLjS4qC9m4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB4752.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(346002)(376002)(39860400002)(396003)(366004)(451199021)(36756003)(86362001)(41300700001)(66946007)(316002)(83380400001)(966005)(4326008)(66476007)(8676002)(6486002)(66556008)(478600001)(44832011)(2906002)(8936002)(5660300002)(38100700002)(186003)(6666004)(6506007)(107886003)(6512007)(1076003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TqH8WL0yh833lCICczAszq4GnDdoDDjBU5PEOITItkGTHP9emogofhqQ1rc+7/+GILUkF9zrKFy8SPnKtpzaRVdXWz774qomJKvru9CUILWVs51P7c7DZUF1wO4zBo6Ilg19EwhQM7WZbMlhZb/ufuwId7F4Ffe+yK1WiZyCYYr/76Zdf078x8x+BqJs8OC1vakH6SBTzPF4tdxkU01r0WOwmQyqhKFyTkKPMFgiH1vIo+0f0YE6sBLIDmkHfQGMNdJJUulkwbwDcWD3SEpoEnuok8/wP/a3GPYiXKGxKtPevjgK9rwUyFnYfIWSbK9DVHZZa7ablRLOQ2X4zU7QhkxGG1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jQf08ypGdhvjMxHqVyBHoy6dGKvvZVTrDkgyNEkq67+fh3JMhaSj0+IV4Kll7/PgghGw/pqYBqCt3IEkgQmJ3ZKraIDLBnOS9ChB6LYbvlpvKiy/UBfYhigGBbv2F7pUcsKrM1iIbfw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c104e925-ed26-49db-f007-08db3b97f2c5 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4752.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2023 20:53:20.4360 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dkbh1fQL01aBSxZmFTEoy36b36PSwhf2tKZMW4GQFxmQbG8ZdAnhFMT8LSvxhmxHAg5BaHNUZRNF/F+8Tevz5w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5548 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-12_11,2023-04-12_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304120178 X-Proofpoint-GUID: 6K85tWasJqlKPJjfbVQroJJJ_uUY1L_j X-Proofpoint-ORIG-GUID: 6K85tWasJqlKPJjfbVQroJJJ_uUY1L_j Precedence: bulk List-ID: Relay files are used by kernel to transfer information to userspace, these files have permission 0400, but mmap is supported, so they are blocked by lockdown. But since kernel just generates the contents of those files while not reading it, it is saft to access relay files in lockdown mode. With this, blktrace can work well in lockdown mode. v2 <- v1: Fix build error when CONFIG_RELAY is not defined. Reported-by: kernel test robot Link: https://lore.kernel.org/oe-kbuild-all/202304121714.6mahd9EW-lkp@intel.com/ Signed-off-by: Junxiao Bi --- fs/debugfs/file.c | 9 +++++++++ include/linux/relay.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 1f971c880dde..c52c94e20366 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "internal.h" @@ -142,6 +143,11 @@ EXPORT_SYMBOL_GPL(debugfs_file_put); * Only permit access to world-readable files when the kernel is locked down. * We also need to exclude any file that has ways to write or alter it as root * can bypass the permissions check. + * Exception: + * Relay files are used by kernel to transfer information to userspace, these + * files have permission 0400, but mmap is supported, so they are blocked by + * lockdown. But since kernel just generates the contents of those files while + * not reading it, it is saft to access relay files in lockdown mode. */ static int debugfs_locked_down(struct inode *inode, struct file *filp, @@ -154,6 +160,9 @@ static int debugfs_locked_down(struct inode *inode, !real_fops->mmap) return 0; + if (is_relay_file(real_fops)) + return 0; + if (security_locked_down(LOCKDOWN_DEBUGFS)) return -EPERM; diff --git a/include/linux/relay.h b/include/linux/relay.h index 72b876dd5cb8..914f116d826e 100644 --- a/include/linux/relay.h +++ b/include/linux/relay.h @@ -279,8 +279,16 @@ extern const struct file_operations relay_file_operations; #ifdef CONFIG_RELAY int relay_prepare_cpu(unsigned int cpu); +static inline int is_relay_file(const struct file_operations *fops) +{ + return fops == &relay_file_operations; +} #else #define relay_prepare_cpu NULL +static inline int is_relay_file(const struct file_operations *fops) +{ + return 0; +} #endif #endif /* _LINUX_RELAY_H */