Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp152294lqs; Thu, 13 Jun 2024 06:40:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/X0IGm8KezZr7lnGk3nJs/Xh5lXu/fRtReNx/aQwUsBhg3Bb4/u5IYY0fhBq2hKy0oY1d5ds0lhwIcZXPmJsGu3gAatoHxipq6ceBIw== X-Google-Smtp-Source: AGHT+IFHXAg6+7LWm57KJrFUONfDRTR3axCP0F8M4IuM9npDSQT28KvwRhPJdJYJ0GP920vRxeZA X-Received: by 2002:a05:6214:2f0d:b0:6b0:705b:54e3 with SMTP id 6a1803df08f44-6b1a60b8b82mr55515636d6.30.1718286035136; Thu, 13 Jun 2024 06:40:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718286035; cv=pass; d=google.com; s=arc-20160816; b=pC+V6CtDd63tcCQhTCf8fdTtrtyvtAOC3JgKVyWn7t/GVOnH5yEZ/Fope4UEVTW/Tg Ls58VP+fhzWt/iHhwKlj5JNy6UY6tCWeZ9LD97KmAHrB+z8oBvM/kUwl0Yj7jWasQsZv 63wnzpSlHwai/bFxuEQH1v2gtNhCXMEPxY/Rzc3mFst4Wwv+8bbYf0+QToiv+Wqr0u6z MdJ/ZpMxaH3BfYwy6EOV/8TpdCqy/djkzQKNy+JLIxmPJyP5vOLkpAssrtt5YOdzeLke vPN8zLplmcwH6JNnEW1lFxHg7J+7UQvPTEAk+shhMteqpW3/kWxQaX5xjeDwnvKRZWNd EOBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=cmKUN7HBX5JwvZVFEChxhiIzGWsEcRksrOahQvM9zAs=; fh=fFe0YM7rvIZ7plMiIVoz9NO+/tJZGvSn25M3dKDD2vw=; b=ZmHVx8v0J9z9WoxG60smf/2wqXgRKGCqTEy7AGj2CpnySjqzPi7atz4Kc5ptY3imro UTBAOp1bcL/6BPkli4lpxeZmTtWO/pD5LA6JIKg1AwR15teArzYbiypOjxIGFaK7jlYX HKQoJQKulXLHP3lL/NrqmWXQRJh8qVxm5WNOS0WLeB7CFLrk27Gx8XubbthtnmU1q9Gd b+I5wHkXPj4mAPKi7MInfo6ZPmq0Vn/48a77YEDQmYfYjCOSPuqTs/Cx0rpmfjfPYBlf kn7mIuQMbYuK3qHUgNfSPZcEZeW4wS/7ov9EhtdMnOy08wXx/rFmoPpf3plLnpHrwwwN zKsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=rCIvFHUB; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-213342-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213342-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6b2a5afcfd5si15144306d6.205.2024.06.13.06.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:40:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213342-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=rCIvFHUB; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-213342-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213342-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C91AE1C222A8 for ; Thu, 13 Jun 2024 13:40:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B051145330; Thu, 13 Jun 2024 13:40:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="rCIvFHUB" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5806143895; Thu, 13 Jun 2024 13:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286010; cv=none; b=UmsiR6HU+u+IQolx6smPXS+E2fya7i/7TTMyLzogy3dqGVWjrXwnYXjo87A87mUCUfR5VOJJ/qANudHCVZGALz/eOnEmUS3SrnR+A73XnjREjI4SEyldLcSgKcosGOEseNTdwsp9pdzv0CfO9Y2zqHXGy03l7uM16g1mvp0Fg1w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286010; c=relaxed/simple; bh=mM/nGXvzfhzKRjtNF5lAJbBStRl1RPZ5BZMncy1sL9k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GnZ8gL+7nnAPUxQaw7Occ6gW9p7z/ewM/Lqe76FgN65d53EEq42gWCpakkEHybNFE7SLhbtOKqbpqqHABr9In6KTt5kRUUGJvrT8OtZlr/9tugp4kt9pqyVeQXZ2J1/qmXeS+oZCSp6MktREwBD2BufeQwfjeE3nc8e/gQcFFaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=rCIvFHUB; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1718286006; bh=mM/nGXvzfhzKRjtNF5lAJbBStRl1RPZ5BZMncy1sL9k=; h=From:To:Cc:Subject:Date:From; b=rCIvFHUBsO5NZzLnUDiHYsWRCOzH0+8w/ag1XyrR9PX/x4XX/uvnkxNzv2d8nVntG y1Ld3hgr80TjTw6qLpnRICkElS4/mOugMovzdvHzFL1bp4NQzRJxIvGDS4rmlLYtru EsJsllDL3M8DLJFdg1qda0xd6Cp657KA/gmNDhHEcf+AnPsalZMPDYh1MypzvlmHZ9 8fokoOZdOKqkSda4rutLNAGUU7ulLq4Yv75KS1ON1rLT/jverE/Cw7HoYARRgjAZbn M/EWDvTqj1INdyeABnul94j2PB3HrSfxNHQArDomMU1SgliiFiwS+2dl5zbkEEzEwo VxA9WdqQL8bnA== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: aratiu) by madrid.collaboradmins.com (Postfix) with ESMTPSA id EA0C037820CD; Thu, 13 Jun 2024 13:40:05 +0000 (UTC) From: Adrian Ratiu To: linux-fsdevel@vger.kernel.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, linux-doc@vger.kernel.org, kernel@collabora.com, gbiv@google.com, ryanbeltran@google.com, inglorion@google.com, ajordanr@google.com, jorgelo@chromium.org, Adrian Ratiu , Jann Horn , Kees Cook , Christian Brauner , Jeff Xu , Kees Cook Subject: [PATCH v6 1/2] proc: pass file instead of inode to proc_mem_open Date: Thu, 13 Jun 2024 16:39:36 +0300 Message-ID: <20240613133937.2352724-1-adrian.ratiu@collabora.com> X-Mailer: git-send-email 2.44.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The file struct is required in proc_mem_open() so its f_mode can be checked when deciding whether to allow or deny /proc/*/mem open requests via the new read/write and foll_force restriction mechanism. Thus instead of directly passing the inode to the fun, we pass the file and get the inode inside it. Cc: Jann Horn Cc: Kees Cook Cc: Christian Brauner Cc: Jeff Xu Signed-off-by: Adrian Ratiu Reviewed-by: Kees Cook --- No changes in v6 --- fs/proc/base.c | 6 +++--- fs/proc/internal.h | 2 +- fs/proc/task_mmu.c | 6 +++--- fs/proc/task_nommu.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 72a1acd03675..4c607089f66e 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -794,9 +794,9 @@ static const struct file_operations proc_single_file_operations = { }; -struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode) +struct mm_struct *proc_mem_open(struct file *file, unsigned int mode) { - struct task_struct *task = get_proc_task(inode); + struct task_struct *task = get_proc_task(file->f_inode); struct mm_struct *mm = ERR_PTR(-ESRCH); if (task) { @@ -816,7 +816,7 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode) static int __mem_open(struct inode *inode, struct file *file, unsigned int mode) { - struct mm_struct *mm = proc_mem_open(inode, mode); + struct mm_struct *mm = proc_mem_open(file, mode); if (IS_ERR(mm)) return PTR_ERR(mm); diff --git a/fs/proc/internal.h b/fs/proc/internal.h index a71ac5379584..d38b2eea40d1 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -295,7 +295,7 @@ struct proc_maps_private { #endif } __randomize_layout; -struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode); +struct mm_struct *proc_mem_open(struct file *file, unsigned int mode); extern const struct file_operations proc_pid_maps_operations; extern const struct file_operations proc_pid_numa_maps_operations; diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f8d35f993fe5..fe3b2182b0aa 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -210,7 +210,7 @@ static int proc_maps_open(struct inode *inode, struct file *file, return -ENOMEM; priv->inode = inode; - priv->mm = proc_mem_open(inode, PTRACE_MODE_READ); + priv->mm = proc_mem_open(file, PTRACE_MODE_READ); if (IS_ERR(priv->mm)) { int err = PTR_ERR(priv->mm); @@ -1030,7 +1030,7 @@ static int smaps_rollup_open(struct inode *inode, struct file *file) goto out_free; priv->inode = inode; - priv->mm = proc_mem_open(inode, PTRACE_MODE_READ); + priv->mm = proc_mem_open(file, PTRACE_MODE_READ); if (IS_ERR(priv->mm)) { ret = PTR_ERR(priv->mm); @@ -1754,7 +1754,7 @@ static int pagemap_open(struct inode *inode, struct file *file) { struct mm_struct *mm; - mm = proc_mem_open(inode, PTRACE_MODE_READ); + mm = proc_mem_open(file, PTRACE_MODE_READ); if (IS_ERR(mm)) return PTR_ERR(mm); file->private_data = mm; diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c index bce674533000..a8ab182a4ed1 100644 --- a/fs/proc/task_nommu.c +++ b/fs/proc/task_nommu.c @@ -259,7 +259,7 @@ static int maps_open(struct inode *inode, struct file *file, return -ENOMEM; priv->inode = inode; - priv->mm = proc_mem_open(inode, PTRACE_MODE_READ); + priv->mm = proc_mem_open(file, PTRACE_MODE_READ); if (IS_ERR(priv->mm)) { int err = PTR_ERR(priv->mm); -- 2.44.2