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 2AE28C71150 for ; Thu, 29 Aug 2024 00:18:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A2396B00D9; Wed, 28 Aug 2024 20:18:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94F696B00DB; Wed, 28 Aug 2024 20:18:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C93E6B00DC; Wed, 28 Aug 2024 20:18:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 582056B00D9 for ; Wed, 28 Aug 2024 20:18:00 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 07EB440241 for ; Thu, 29 Aug 2024 00:18:00 +0000 (UTC) X-FDA: 82503370320.18.53ED1D9 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf25.hostedemail.com (Postfix) with ESMTP id 2F6EDA000C for ; Thu, 29 Aug 2024 00:17:57 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Q7q2uKup; spf=pass (imf25.hostedemail.com: domain of kees@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724890591; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=thFD+zwrU/b8IjAzPx4YCVy572Egc1cifaiMkOgAEUY=; b=EedcFVZxzoXocgCzKaQuKkWeh/pbzasp8+AKR2hZucWws37SR5MC1t9Kfrz73SQ7amYZBS n4UNnD+DPervia1DMbXmjy/EhkaPiFz/CspCGf/crvODbDRbk3FiHRjXpBl2d2Txp8Ja4o pFFb/xiaFNGsgxova/zn4qAB4ODdMS0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724890591; a=rsa-sha256; cv=none; b=LHnoL/TnhFxgaR9iLEIgcFnifG9PH8i5Q88GtybzBkixFMikxC4pscpSD9jhUeOQ8wUlO8 +ZARp3D2i5cGvUX4QNiC3qgJJfZNNdBuB8xLyTMiACT5yxT9LpFloLqyfdXT+4VBlYrwCp l/a+C5E7YxE+ofrdt3iibtxFfAU3zSg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Q7q2uKup; spf=pass (imf25.hostedemail.com: domain of kees@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id D2CC8AE40F2; Thu, 29 Aug 2024 00:17:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA5D1C4CEC0; Thu, 29 Aug 2024 00:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724890675; bh=wqwfbglmiOW3zEjrozGHbRY21H9OrGw1J7tCUk4qVjg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q7q2uKupXiWrXEb5VBisQRcVpWz1lLcSeE7zINvaSJm8aB8JKzaa1Qlj4qvHMl9T/ mB0q0BY6SVtNcYAr1aQd4hYDHFHib8zZ9wUNt5pkZkagn7QUYxvdthCYydJEcS6isS EIaBZgHBZegmK+8STHem6es+CstqnY94jKsuJoGG9Eu4OXFZpHJMWmXP/XUZReh9Ty SwdIv0b0X/rYgMw8zApCJK8AIPIiB13V8lLrSIAOdunytxsuwfeR+sQxj1xQwuY7Db UT7C88ojT+76hQqBGXasE9vK2f5kOA2shjJvfoKnyQ6Bq2qrQ6C6FSIanWfsDiAHqV G4c5NZzYW7RGA== Date: Wed, 28 Aug 2024 17:17:55 -0700 From: Kees Cook To: Alejandro Colomar Cc: Yafang Shao , akpm@linux-foundation.org, torvalds@linux-foundation.org, justinstitt@google.com, ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, penguin-kernel@i-love.sakura.ne.jp, 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, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, Alexander Viro , Christian Brauner , Jan Kara , Matus Jokay , "Serge E. Hallyn" Subject: Re: [PATCH v8 1/8] Get rid of __get_task_comm() Message-ID: <202408281712.F78440FF@keescook> References: <20240828030321.20688-1-laoar.shao@gmail.com> <20240828030321.20688-2-laoar.shao@gmail.com> <7839453E-CA06-430A-A198-92EB906F94D9@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 2F6EDA000C X-Stat-Signature: 9jo46gt8f7rraxahjusi1nj3xm3p7694 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724890677-893879 X-HE-Meta: U2FsdGVkX1/eS0Tdbi2Jq16mfxz4f8N0zTC/j04GvUNV3BLpqMqFmoJiRwPB7PVB/diLeudFIVyBpAp+pLnPM5g6ADAAkUIHNiaf7KTN2IvdFW97ZLbUpi0vUYZQTG6YaPxFWRiKuec0hC1YH8YBYghNrDY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nV5h5ZZIsHD78Qwb+xIMrkit3zeo8v+C9g58DwDL9n900z3Sa0OO2a8OewvnLBSRA+NtNEzTbtVeWGbuudcYC3E0Rm9qZQnGlHIpW60jJbN1exW7C/h6u00pwdt5Fm9qZc4GO4ipSnJFyDZAFov6upaA2GDF1Ph5AKqb2ZjV4f7b2cVYn6OHKOhpUvCPZqosmllnCrMwYZeuo= 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: On Wed, Aug 28, 2024 at 05:09:08PM +0200, Alejandro Colomar wrote: > Hi Kees, > > On Wed, Aug 28, 2024 at 06:48:39AM GMT, Kees Cook wrote: > > [...] > > > >Thank you for your suggestion. How does the following commit log look > > >to you? Does it meet your expectations? > > > > > > string: Use ARRAY_SIZE() in strscpy() > > > > > > We can use ARRAY_SIZE() instead to clarify that they are regular characters. > > > > > > Co-developed-by: Alejandro Colomar > > > Signed-off-by: Alejandro Colomar > > > Signed-off-by: Yafang Shao > > > > > >diff --git a/arch/um/include/shared/user.h b/arch/um/include/shared/user.h > > >index bbab79c0c074..07216996e3a9 100644 > > >--- a/arch/um/include/shared/user.h > > >+++ b/arch/um/include/shared/user.h > > >@@ -14,7 +14,7 @@ > > > * copying too much infrastructure for my taste, so userspace files > > > * get less checking than kernel files. > > > */ > > >-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) > > >+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x)) > > > > > > /* This is to get size_t and NULL */ > > > #ifndef __UM_HOST__ > > >@@ -60,7 +60,7 @@ static inline void print_hex_dump(const char *level, > > >const char *prefix_str, > > > extern int in_aton(char *str); > > > extern size_t strlcat(char *, const char *, size_t); > > > extern size_t sized_strscpy(char *, const char *, size_t); > > >-#define strscpy(dst, src) sized_strscpy(dst, src, sizeof(dst)) > > >+#define strscpy(dst, src) sized_strscpy(dst, src, ARRAY_SIZE(dst)) > > > > Uh, but why? strscpy() copies bytes, not array elements. Using sizeof() is already correct and using ARRAY_SIZE() could lead to unexpectedly small counts (in admittedly odd situations). > > > > What is the problem you're trying to solve here? > > I suggested that here: > > > There, you'll find the rationale (and also for avoiding the _pad calls > where not necessary --I ignore if it's necessary here--). Right, so we only use byte strings for strscpy(), so sizeof() is sufficient. There's no technical need to switch to ARRAY_SIZE(), and I'd like to minimize any changes to such core APIs without a good reason. And for the _pad change, we are also doing strncpy() replacement via case-by-case analysis, but with a common function like get_task_comm(), I don't want to change the behavior without a complete audit of the padding needs of every caller. Since that's rather a lot for this series, I'd rather we just leave the existing behavior as-is, and if padding removal is wanted after that, we can do it on a case-by-case basis then. -Kees -- Kees Cook