Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp980484lqp; Thu, 23 May 2024 06:04:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWz6WrvwtDFtYmSJkvjAg+sGkD6yWAaci2fscoKjopMXjS5ge9eSxy1yA+Kaww3wygoB2/OUUPECp6vFSDk2S5+eosTU6abMRmyICjyMw== X-Google-Smtp-Source: AGHT+IFXipSJQPeK9joQLG0a/zSeFYV7erqD+6ZUAoaI/kHZdudwsHXMEblxAfFctoHx/6sGYNlF X-Received: by 2002:a17:906:6d7:b0:a59:a112:add2 with SMTP id a640c23a62f3a-a622818f1f9mr360896566b.69.1716469464168; Thu, 23 May 2024 06:04:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716469464; cv=pass; d=google.com; s=arc-20160816; b=cd53JCvH+VhWXuV3SU1XZZ7d3hTqxCrC7FggGgjXREPBRBcbVODZ9QiqajJLDIJ3VF wIPIgQSHMYR14Q6+3ndSzG6BuyJTIIqIImvnFTIdDD9H9utIbEDkcgGvYB8lCBpHCQCU YQyYRHl/pws5UsLCDmT+2WV6C9GfyfshnOh1Pvzdawd6GXQYLgbGqehEKYvf0ihBeOUZ KCSUWUHVXuCqcL+EjQ4TrrX0087O9PuTd4+hP43IvCKVJcaOjj/0gzNSAAI7vvn9bvSF IDBFZrgl4AbmlM1QYfVn7Fk9JUhljxCaBfIAAu4VZ1+/rqWETLlh3aXMKk/kvUkkmRsl MZtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=QugtyGwjGbAPX1Dy+otOhYo8FoEI57emQEUwIRWflfs=; fh=6aJv0SD82+fTsh0LVcxIjLPWsag+nVrZbcyEWsjN4DM=; b=zsCnXoXzn4Q/LIwo2Oo8xKXxwDCKe5klp1fbQbiq3LUmNAkbFP8BUezpLQv6aQNI5T Np5vY3VzA2798+sr1DpLTgATyff/5YmYU46MkmlTR7MM0q3oExVL7cwrDicYKAroJcKo OVQ6jVqg8BlQ3ovbGxJk7y8cAnhgp14NrhKqkL0px80ASTYAiHqE+QOibW69juRRa0sp SGwvxfOSS6mkYA9eackUBA+OYPNDrGJ9qJ4vGIAbdHFxDdGSgzqBrOfsKFNsRQCf77uq J5KzB+aLye0jtnkmJE21NKZQFhT53tXuW32tx8JxhnPeyvkDYahv7kLrLt4CvJrYBdKy Ai8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dbMXaBOI; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-187538-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187538-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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-a5a17c2c4c7si1623689166b.978.2024.05.23.06.04.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 06:04:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187538-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=@gmail.com header.s=20230601 header.b=dbMXaBOI; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-187538-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187538-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 B1CBD1F23564 for ; Thu, 23 May 2024 13:04:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4936914A4EC; Thu, 23 May 2024 13:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dbMXaBOI" Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E113713C8FF; Thu, 23 May 2024 13:04:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716469454; cv=none; b=LKOsj4XsS5uFMDu2DVavf3/qP42JBxcn5FMTRlcF0+N2NuaoO0s2Wyl8ZDbbRIRNI66NqmbrH9Us39XjP1QRkOXJS2rHb4h2vLqdjRhOOU0URZ3Ide8Mv3pg4pOjmnKsEQ2zFPU4nKCHpD/sGKxpUtG/mIiFA8y122W3oFmKzTE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716469454; c=relaxed/simple; bh=bxGtTWy1GarmuvLvpXcuxsTNg8vH5BafRYt5eBpbYc0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=UwV0pJqgWBjhWE/VskC0RmZlElYSZG4qEOzhky/aa+emZRVZLCgovMPLdT75sQk/aBg3Ws5Sd17CP8v9olLZxrJB5o06uqp7JDnd3cH/qIB48yZcRrjEfdAwEh93s0WlW7twSlWlNHBgG8hCJ3DTtC6XAJ/w41rjtBzhbWHjuVQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dbMXaBOI; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6ab8e759adbso8113376d6.0; Thu, 23 May 2024 06:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716469452; x=1717074252; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QugtyGwjGbAPX1Dy+otOhYo8FoEI57emQEUwIRWflfs=; b=dbMXaBOIQoKcY/5KSXWogpbta2OStdp7+PqAp6mBvKTHufl0W6hb/8A5L0v4A+09qD 36WrXU2gG15c1zA62QawOAhB1gVUKDXwZyAqNi/upBJaSWQHnBr7u8NJXs2IBPC2b1Sk jD/O+2N9IzVCwWcQf8jSP9fSo5QS95w6SBDd3JmlhLz5R6OyTj/TFYlDWtRAyak6ftdt ybEjpzAiuRcMyKvmh3DxRVIRZnjsf2mObtMTZTmfnHQqbz37+B9ktNJD0tEhPy72D/b5 uhNsFwpYHcgz4LzUvHAHqQuG7av3X7wX1xbNxQw9t66Cw76yyjdg6iAfRotzC7wJ5MUe xoMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716469452; x=1717074252; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QugtyGwjGbAPX1Dy+otOhYo8FoEI57emQEUwIRWflfs=; b=h74sKuE92EeBEs/b6VuMrrcbmvxuoEFCOzi/FhlIW/t5U5VQFdYCcTs4eHIQDZSVSk fTO7vz3BdV4QXH3a6FUnB+9bDhqP/2WbShdEBuvrj45GGeg/w4BDQ6ci3+rHeHqp6BwS m7k/zaPfav+ipICo68sVosT+bwIykrOPfsHVMFxOft2CtRcxUuLFuk5ylCDR7D9FJ7+r IvPnM/9Z+URM9Gri0hcFyXxePh7L9r8JNtAyQTYl7pjyjVxBKNYGROBOJF7d95DM1L21 Hut+xJ4qvJRE1pN7/ZmPZ7Ul9CGNn9AR+z18Y7p+HWVW9/VIRuD0wFdAXixU1kBPvKJ0 HYiw== X-Forwarded-Encrypted: i=1; AJvYcCWulJkvp8gzcUcGQsVHQ+z7OnzyYmaRzTLORdia/QTBy9tVeJwL/iAPB+tsvJn95LZuyKoaTB4qejibI4l0NVZQ90inuMi/hhUrB458 X-Gm-Message-State: AOJu0YzrKs9+wMwFHffv9DBB94NteghpkJMcmau/tZdY4kF5c0XAoi4f Y4AShucbMbJBp2jnoUErW7GhsbSbV9iLQEFWtcXObLvdCUzYcnhXDgpkcujN+9sSj1NnMdj9Hvb Jlh2SIXmM9y/JF4RZ/dYgYh0WrDc= X-Received: by 2002:a05:6214:19e3:b0:6aa:39a7:a63d with SMTP id 6a1803df08f44-6ab8f60c45bmr36919296d6.32.1716469451550; Thu, 23 May 2024 06:04:11 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Yafang Shao Date: Thu, 23 May 2024 21:03:34 +0800 Message-ID: Subject: Re: [PATCH workqueue/for-6.10-fixes] workqueue: Refactor worker ID formatting and make wq_worker_comm() use full ID string To: Linus Torvalds Cc: bpf , Tejun Heo , Jan Engelhardt , Craig Small , linux-kernel@vger.kernel.org, Lai Jiangshan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 23, 2024 at 12:32=E2=80=AFPM Linus Torvalds wrote: > > On Wed, 22 May 2024 at 19:38, Yafang Shao wrote: > > > > Indeed, the 16-byte limit is hard-coded in certain BPF code: > > It's worse than that. > > We have code like this: > > memcpy(__entry->comm, t->comm, TASK_COMM_LEN); > > and it looks like this code not only has a fixed-size target buffer of > TASK_COMM_LEN, it also just uses "memcpy()" instead of "strscpy()", > knowing that the source has the NUL byte in it. > > If it wasn't for that memcpy() pattern, I think this trivial patch > would "JustWork(tm)" > > diff --git a/fs/exec.c b/fs/exec.c > index 2d7dd0e39034..5829912a2fa0 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1239,7 +1239,7 @@ 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); > + strscpy_pad(buf, tsk->real_comm, buf_size); > task_unlock(tsk); > return buf; > } > @@ -1254,7 +1254,7 @@ void __set_task_comm(struct task_struct *tsk, > const char *buf, bool exec) > { > task_lock(tsk); > trace_task_rename(tsk, buf); > - strscpy_pad(tsk->comm, buf, sizeof(tsk->comm)); > + strscpy_pad(tsk->real_comm, buf, sizeof(tsk->real_comm)); > task_unlock(tsk); > perf_event_comm(tsk, exec); > } > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 61591ac6eab6..948220958548 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -299,6 +299,7 @@ struct user_event_mm; > */ > enum { > TASK_COMM_LEN =3D 16, > + REAL_TASK_COMM_LEN =3D 24, > }; > > extern void sched_tick(void); > @@ -1090,7 +1091,10 @@ struct task_struct { > * - access it with [gs]et_task_comm() > * - lock it with task_lock() > */ > - char comm[TASK_COMM_LEN]; > + union { > + char comm[TASK_COMM_LEN]; > + char real_comm[REAL_TASK_COMM_LEN]; > + }; > > struct nameidata *nameidata; > > and the old common pattern of just printing with '%s' and tsk->comm > would just continue to work: > > pr_alert("BUG: Bad page state in process %s pfn:%05lx\n", > current->comm, page_to_pfn(page)); > > but will get a longer max string. > > Of course, we have code like this in security/selinux/selinuxfs.c that > is literally written so that it won't work: > > if (new_value) { > char comm[sizeof(current->comm)]; > > memcpy(comm, current->comm, sizeof(comm)); > pr_err("SELinux: %s (%d) set checkreqprot to 1. This > is no longer supported.\n", > comm, current->pid); > } > > which copies to a temporary buffer (which now does *NOT* have a > closing NUL character), and then prints from that. The intent is to at > least have a stable buffer, but it basically relies on the source of > the memcpy() being stable enough anyway. > > That said, a simple grep like this: > > git grep 'memcpy.*->comm\>' > > more than likely finds all relevant cases. Not *that* many, and just > changing the 'memcpy()' to 'copy_comm()' should fix them all. > > The "copy_comm()" would trivially look something like this: > > memcpy(dst, src, TASK_COMM_LEN); > dst[TASK_COMM_LEN-1] =3D 0; > > and the people who want that old TASK_COMM_LEN behavior will get it, > and the people who just print out ->comm as a string will magically > get the longer new "real comm". > > And people who do "sizeof(->comm)" will continue to get the old value > because of the hacky union. FWIW. > > Anybody want to polish up the above turd? It doesn't look all that > hard unless I'm missing something, but needs some testing and care. If it's not urgent and no one else will handle it, I'll take care of it. However, I might not be able to complete it quickly. --=20 Regards Yafang