Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp767717lqb; Fri, 24 May 2024 12:30:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVcoYOZlWqEmylTKqSqFOaFEQwG+76BHB/CjRN9BmBIP/LaWAzKcnIHuMxtaEPeVdMHJOQYpJr55w8Eww5ClaYHmdF3wF7OPvw0ksO9xw== X-Google-Smtp-Source: AGHT+IGC8yfTS1DX9Vs9BwLQiaSB0gyke5vzZYMR8/FCDWtLxqrOGYRseurbbD5wQF5YAD1//b/5 X-Received: by 2002:a17:906:55d1:b0:a59:c319:f1db with SMTP id a640c23a62f3a-a62640779b9mr224547066b.1.1716579000539; Fri, 24 May 2024 12:30:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716579000; cv=pass; d=google.com; s=arc-20160816; b=EH2Aq3NBNcmlAWVeK0yx8kSARa6Cs12VlQAXNMA4cnTZETZ24dReYhGk9dYKhBrioV AEPH9ntUwCTvK0P49H9hsQO3OzUCp6qYaQB98R3J7CAAVbgQf7qiSpLHSwIXQijwEtMd bHj+AW8z0t9Ebj3QJIhcFTd1694nuhr3aQ/JJvPficRTyLhfuSaz9rjuv89o9WGr2zGy 8WwubJTkeEOXRNtJm3+GLP9zQV5dh/ntH8WsY5Keo6Xi9o6H755ApuaImowPEIiWIg1T 11847/BpgBs7CYwz4dE0qNpRGUfGoLRCzR1Bt2l6S8Bxh0cbL6KY2/iOEMcNomu0DEcN dHUA== 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=qy7YqgDyXh2CY45F6/rpudKHC4G6/rIKe2aA+kAajno=; fh=m/CV98fFO1yjJc7XGszl6jfKbvxw6do8aQUlwkwRVT8=; b=ZrCdha0Qr24QJcbCTDrqb7h6dfwaw9lSX3hafzng/az2VdTbwkj15X7/tXnZ7ifEds zzV9JvzIc15n9y24X7KnZVThnwwzUjYNS3bEwDbWhAJfOytnQiHWNkTNO8WECvy/isK1 mosD6GvVOWvj7+lPLWUkmqjDx+gxndh3RWtaJ5poQQu0Q9bhIJUEfjAbu5b3mhi2atmq 9VG8TCHYf0WWsrjyD1usRl60/HBZH1MyKN29IadMTBiA/IrKm1PvP2pFiKJZ5U7TByvW tZGccMSBUXE+UnNn8ixauuXX0twsmNflBByMkCgImxtZjYwu0fQeERhLJXYS1bbnLhSu yfKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Pf1+u5er; 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-189045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189045-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626c80530dsi104176466b.19.2024.05.24.12.30.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 12:30:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Pf1+u5er; 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-189045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189045-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 44DC71F21561 for ; Fri, 24 May 2024 19:30:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B32E5914C; Fri, 24 May 2024 19:29:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="Pf1+u5er" 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 1AB72433BB; Fri, 24 May 2024 19:29:45 +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=1716578987; cv=none; b=AaLHfi7imBQousaAwq1jNnqwwsHMRUqrZF/34nXIQJ0wqAv0yPQMX0TGd7FeWb8shYn7rhf8nzQUop+yphg7dSx/m7lR1EYToLR02xFnPqNe4da9iZUPbswKhqp2TxkmAGfBEzme9VfS3AryRUzt4gW/laLBP6ECPnPKi+D7Fig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716578987; c=relaxed/simple; bh=WmPIFGX+ZJkkhj6YLNT+xJYHijtzNwQllcZAiZDdrUk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KhskuXuiOwsHIyHsFrEsMLCYfMCk9MpJ2rX+KSChIpNLiTChHoKJFHZjqGQdXQhD/vypkyRQbdtqMPTf9STGqqPr7/r/joc4/orxpDfCQnbaoxkkes4wWe3eXafhXsHlRh8WnyM4TGDG1hr/iG5vaPsyKaD72OnDfDAdkEdKlyQ= 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=Pf1+u5er; 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=1716578984; bh=WmPIFGX+ZJkkhj6YLNT+xJYHijtzNwQllcZAiZDdrUk=; h=From:To:Cc:Subject:Date:From; b=Pf1+u5er/a1za+nTnktjqBqhN7FOcJ9SJHlj+pB2euGyHU69RJdU8D+CmjSEJFAx6 nRmnuEjDbYIzDGRRH9xbsx484DrZT4vdjIOR/za6q2Ki7V3OmMbE8+Vqalb/r6gtvM Ilh7hBuopUJ9WuXDYK3hD83SIEbxywF3lCovycGuNr18XQhS4Se7v4UoO9kKB9taaK CVUqIlQfxCXuuEUPRcquFpzlEW5ihHYaonWVfBWYFc9HEQSbL3ar9wQ45yOTqCSBev 8hXBmgOIukH9XC2uLDi+wWKXfKo6WfZ47hBihcdMiywKv5NO1oiIvIemb02dbEyr/s uE2DatGXxk+/Q== 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 5AC023782163; Fri, 24 May 2024 19:29:43 +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 Subject: [PATCH v4 1/2] proc: pass file instead of inode to proc_mem_open Date: Fri, 24 May 2024 22:28:57 +0300 Message-ID: <20240524192858.3206-1-adrian.ratiu@collabora.com> X-Mailer: git-send-email 2.44.1 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 Signed-off-by: Adrian Ratiu --- * New in v4 --- fs/proc/base.c | 6 +++--- fs/proc/internal.h | 2 +- fs/proc/task_mmu.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 18550c071d71..6faf1b3a4117 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 e5a5f015ff03..dc9abbf662be 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); @@ -1025,7 +1025,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); @@ -1749,7 +1749,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; -- 2.44.1