From patchwork Sun Jun 2 02:37:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13682614 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD039C25B7E for ; Sun, 2 Jun 2024 02:38:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 659666B009A; Sat, 1 Jun 2024 22:38:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60A4C6B009E; Sat, 1 Jun 2024 22:38:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AA726B00A0; Sat, 1 Jun 2024 22:38:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 290456B009A for ; Sat, 1 Jun 2024 22:38:24 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 79F6A12127F for ; Sun, 2 Jun 2024 02:38:23 +0000 (UTC) X-FDA: 82184389686.26.B622BFB Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf09.hostedemail.com (Postfix) with ESMTP id A0349140005 for ; Sun, 2 Jun 2024 02:38:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=asJ0zeyN; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717295901; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eDSXYBnkhoFlTFb/2ZctlhGfFi3vGVZVEbq0hz4eBkQ=; b=1sU6l8ojaaxqWoe/l79mGJsCGiSfc64MKRc0eqoipr8GZ1oLtiPTUPlb7zYlY9ZoQObb8f NspqhplLJIA5wUBL4pwhAp52EldaZW++0Gyrb9jAbQymYpuAfo2cAr3XLKW+gocL0dbqJU ZKgeTKK+g3dqJLuRwpvb7vU66Wm8baY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717295901; a=rsa-sha256; cv=none; b=AO5hKTONmt84dRBYjPYtGpyi3IEzRCY4uWD7GSS9iTPkVr2fK34ZPgowe7o0NznpTsUGHC ZcTtERRXiLnqeQmgTeFS0WMKifOAoH8woMEdJDDTK24bRjG8cbRsWQujiYN1anYSBMQUyS b0ElONqV2QsZ9QnJkd/uC7dHh/+bCeU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=asJ0zeyN; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-652fd0bb5e6so2617741a12.0 for ; Sat, 01 Jun 2024 19:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717295900; x=1717900700; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eDSXYBnkhoFlTFb/2ZctlhGfFi3vGVZVEbq0hz4eBkQ=; b=asJ0zeyN+StzyqN9FUXt8zXs6CHUIJPOvep28XcM5LMEVmFP4zM5znmqycIofmcE+d PhxKUlLU3iy66fNvW6ZmnHHFjEUPDxdgSpVsI/2eAQjfyS8OZ6LKjhuXd4i0CCvnbo8D 5ah2DIahH7H+aGJo2/Ir3f2aSSIzBUa0U3/MAbm0k3JfvQ7Q2qZPWvVuHdSmIq7B3628 hSoxX7Hdk19+HUR3foH5uf+hHKMxIe51uhbSkwgwlj/0KKQtNt2UE67DKb4J4qWzMmtW cVfTCpPEid0pbZjrxitahUOWTZTAElE29ceZeHC/DOgP/zEvDkpSwiFWcab8UoCg8NBP s9cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717295900; x=1717900700; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eDSXYBnkhoFlTFb/2ZctlhGfFi3vGVZVEbq0hz4eBkQ=; b=ocV4Fwz0Q8U7haRyJI01Yry5r2r0YJQExt4SYESKDLBhVzGecJl+unVRht1ls+/NMy x4OGupAOXKcIWjiubymJw6rRMrjDQGbyL5nRhc5VfHqExqTtDhGrCx+tEmtzScPvfjw6 ypHOE6TCAK6VjTdXt5lUxbOrTaXr2QB6lKo+H/QkNdiWBzomGpurcDSOxiF5mNqeWF+o EEceZ7ikh5KN7EMNTZMESLTHK8dCvMBM+mBI8l2vh/bg+hMi9jgySOL11X9Fi1Qx/tBu vQ4/zLa4QwobQgaM4h4jY9u1LzJZa7Xeze9cMwpgsokLMH6FuoPJNGjwQKdn9VBG45RD dX6A== X-Gm-Message-State: AOJu0YzwpKculPR577iZqEcCCPCgpk7yKWos3wS4O653fG4tSVArHetM Ak0MD/yuDNPnS8q7tEPrLjPHSvn78FLOIJe3/nOaRYj7gpJLoEXU X-Google-Smtp-Source: AGHT+IGSkiCT1T8H8uAL0usG+RhmGH5uSZT9xuU+RtiT09NgmrJQRFy+Yk6pxuNFE1Yrq524r9yvYw== X-Received: by 2002:a17:903:30cd:b0:1f4:7d47:b889 with SMTP id d9443c01a7336-1f6370209femr47779675ad.30.1717295900374; Sat, 01 Jun 2024 19:38:20 -0700 (PDT) Received: from localhost.localdomain ([39.144.45.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323ea21csm39379575ad.202.2024.06.01.19.38.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 19:38:19 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, audit@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, bpf@vger.kernel.org, Yafang Shao , Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook Subject: [PATCH 1/6] fs/exec: Drop task_lock() inside __get_task_comm() Date: Sun, 2 Jun 2024 10:37:49 +0800 Message-Id: <20240602023754.25443-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240602023754.25443-1-laoar.shao@gmail.com> References: <20240602023754.25443-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 9kp8u3zw58o73wodmd9zuysprqii7eko X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A0349140005 X-HE-Tag: 1717295901-888413 X-HE-Meta: U2FsdGVkX182rSaUabumdh4rDIj0fiapUpso+xEgmK/BQiUMo813At8ZMWtoydNsuSURKOufaiWfq5L7uiRoxoVNdZehQjE4C8Ol5Hy+F/AFYlzQ7QB7FkL5qPDo9WgDJWezOwNf6FxoHIbTNFkq56DrsQr3D5u8EvMUmLmHlIKcP5I1KerBWukcaX77NwqAz9So6iOhw27A9JIemSlGnc2nA7udileH+0RcLM8XxlYI1/4oTxracGboEuQEGd41U8MmraCsS6Um2jxLcD8AGF/2wJlz6rKkPr34nLB0sixhpGUNorsuSFVNBku1XaV73Lsqrfr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bFh5Y8xPmLby0B54N5NxeWLH+UBbJcLp9eGjI3CHlfUP/Gk1SbkNNTicmyeV6B69BwlUnHtJm5HkQPVnPohRaGWQg2WfHF2hFoqFYwNkCB9KYHKZJisgxI94WEoY5biymlEUSiqq28pKxTU0bWfjIKazTUuUUsiF31+7HOguXhhPJytOTgi5WbG21ID3XitE/CkoPqoGTt8k6sI8aMapxrybaqF06wwke6S/9pCo+Vj1nibh4B+jlkHltWVQolZrAMio7ByIvX5Fz5JdiDTPZ5Lujg1QVWhJvmseGoweIMPVymwsR26YEI8l0S6ns36sjM8BMzLzjJD18s3zKhFTi3OJjjMwwOfgnfNhEN/5lXwbbeaOAk2jj0oFm+UsX4UuHxZ3yy9w+2IIDqvJkYlx9Ee/1YJImHc+i6s+A1YeyWx5JheKaUmv6YriMY4oXCGCjWHeYLLpFvoKm0xCaKQuxKmfwfoYzqA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Quoted from Linus [0]: Since user space can randomly change their names anyway, using locking was always wrong for readers (for writers it probably does make sense to have some lock - although practically speaking nobody cares there either, but at least for a writer some kind of race could have long-term mixed results Suggested-by: Linus Torvalds Link: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npJooP8chLPEfaFV0oNYTTBA@mail.gmail.com [0] Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook --- fs/exec.c | 7 +++++-- include/linux/sched.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index b3c40fbb325f..b43992d35a8a 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1227,12 +1227,15 @@ static int unshare_sighand(struct task_struct *me) return 0; } +/* + * User space can randomly change their names anyway, so locking for readers + * doesn't make sense. For writers, locking is probably necessary, as a race + * condition could lead to long-term mixed results. + */ char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk) { - task_lock(tsk); /* Always NUL terminated and zero-padded */ strscpy_pad(buf, tsk->comm, buf_size); - task_unlock(tsk); return buf; } EXPORT_SYMBOL_GPL(__get_task_comm); diff --git a/include/linux/sched.h b/include/linux/sched.h index c75fd46506df..56a927393a38 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1083,7 +1083,7 @@ struct task_struct { * * - normally initialized setup_new_exec() * - access it with [gs]et_task_comm() - * - lock it with task_lock() + * - lock it with task_lock() for writing */ char comm[TASK_COMM_LEN];