From mboxrd@z Thu Jan 1 00:00:00 1970 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 E0E5EC27C5E for ; Mon, 10 Jun 2024 12:34:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41FB16B0098; Mon, 10 Jun 2024 08:34:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CD9B6B00A6; Mon, 10 Jun 2024 08:34:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 296CE6B00A8; Mon, 10 Jun 2024 08:34:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 09F226B0098 for ; Mon, 10 Jun 2024 08:34:20 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A53AA80EC1 for ; Mon, 10 Jun 2024 12:34:19 +0000 (UTC) X-FDA: 82214921838.29.B1165E3 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by imf16.hostedemail.com (Postfix) with ESMTP id 77D5418000E for ; Mon, 10 Jun 2024 12:34:16 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=xmission.com; spf=pass (imf16.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.233 as permitted sender) smtp.mailfrom=ebiederm@xmission.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718022856; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yh2ObXonal4Aa6rwXvSwFyXJ/ZHfnabEiRAXU82OiGs=; b=ZBY53aIUtqp5H39nkH3o/u/nWKNQ0zAfn6CP5LoAolYKel2VGSe1TomX+1PVoSBaOnh0dd CbGY1qo7R5yKylhxkVCDxYoD+a/jFhggLP3MXqqfI1TO1vziN8D+n/Nxg8Rigkc8YpKuR2 iPF0V410Qk1hiEJ7iesHPjJFeFNNwE8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=xmission.com; spf=pass (imf16.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.233 as permitted sender) smtp.mailfrom=ebiederm@xmission.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718022856; a=rsa-sha256; cv=none; b=n6c8udM6eZ0rbOgBg2Vz7ei1Eg79c8HZvf1eQaDegYYUggflKa3zudZGbD75ItbeXsphAd hMr4/GhA4sl4hNZvB/CHEVyK3WBB3vfUrBpu6LB73qWE5YF4CqPMRXs2s81RHG0px4BJkC ddIEqJkfPg5BcDH3CaT47iQn9TSHKnM= Received: from in01.mta.xmission.com ([166.70.13.51]:38392) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sGeE1-007QxW-Ub; Mon, 10 Jun 2024 06:34:14 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:54200 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sGeE0-00FROe-SU; Mon, 10 Jun 2024 06:34:13 -0600 From: "Eric W. Biederman" To: Alexei Starovoitov Cc: Yafang Shao , Linus Torvalds , linux-mm , Linux-Fsdevel , linux-trace-kernel , audit@vger.kernel.org, LSM List , selinux@vger.kernel.org, bpf , Alexander Viro , Christian Brauner , Jan Kara , Kees Cook References: <20240602023754.25443-1-laoar.shao@gmail.com> <20240602023754.25443-2-laoar.shao@gmail.com> <87ikysdmsi.fsf@email.froward.int.ebiederm.org> <874jabdygo.fsf@email.froward.int.ebiederm.org> Date: Mon, 10 Jun 2024 07:34:01 -0500 In-Reply-To: (Alexei Starovoitov's message of "Sun, 2 Jun 2024 11:23:17 -0700") Message-ID: <87ikyhrn7q.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-XM-SPF: eid=1sGeE0-00FROe-SU;;;mid=<87ikyhrn7q.fsf@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1+aqS3BV7g8TVW+kULFxysO2TVuiqUO+14= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH 1/6] fs/exec: Drop task_lock() inside __get_task_comm() X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) X-Stat-Signature: hrxq34jrbwk3du8e9odsrr7byg8onj7h X-Rspamd-Queue-Id: 77D5418000E X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718022856-961354 X-HE-Meta: U2FsdGVkX1/DSsotrw1Dh3gLK2dk/eUlXYmpmIIwpl37vFlrjRQXmIhUYC88JjWdC2rcdu3xESKSj3JjjtVwXHpkj9gkliBmnGYesKSCjPZkCdrejjQoFK30JGrrIlGvZiTCW7AEpYV6Hx4seFduKjTzG3dgI08H6dWRAj14bcUsorbozPnw0A857vTAmYVYcJxk8h/MjVKa1g1jDTdAlSiT9X6dNzUOTCTysGuN1LavI8Z4nIFKY3GZ8KJPpG0uA5dCEWyuS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ack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Alexei Starovoitov writes: > On Sun, Jun 2, 2024 at 10:53=E2=80=AFAM Eric W. Biederman wrote: >> >> If you are performing lockless reads and depending upon a '\0' >> terminator without limiting yourself to the size of the buffer >> there needs to be a big fat comment as to how in the world >> you are guaranteed that a '\0' inside the buffer will always >> be found. > > I think Yafang can certainly add such a comment next to > __[gs]et_task_comm. > > I prefer to avoid open coding memcpy + mmemset when strscpy_pad works. Looking through the code in set_task_comm strscpy_pad only works when both the source and designation are aligned. Otherwise it performs a byte a time copy, and is most definitely susceptible to the race I observed. Further I looked a couple of the uses of set_task_com, in fs/proc/base.c, kernel/kthread.c, and kernel/sys.c. Nowhere do I see a guarantee that the source buffer is word aligned or even something that would reasonably cause a compiler to place the buffer that is being passed to set_task_comm to be word aligned. As far as I can tell it is completely up to the compiler if it will cause strscpy_pad to honor the word at a time guarantee needed to make strscpy_pad safe for reading the information. This is not to say we can't make it safe. The easiest would be to create an aligned temporary buffer in set_task_comm, and preserve the existing interface. Alternatively a type that has the appropriate size and alignment could be used as input to set_task_comm and it could be caller's responsibility to use it. While we can definitely make reading task->comm happen without taking the lock. Doing so without updating set_task_comm to provide the guarantees needed to make it safe, looks like a case of play silly games, win silly prizes. Eric