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 2926CC3ABBF for ; Wed, 7 May 2025 11:05:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60B526B0099; Wed, 7 May 2025 07:05:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BC626B009A; Wed, 7 May 2025 07:05:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45DA16B009B; Wed, 7 May 2025 07:05: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 23C656B0099 for ; Wed, 7 May 2025 07:05:24 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1AC41141519 for ; Wed, 7 May 2025 11:05:24 +0000 (UTC) X-FDA: 83415830568.19.B9DF20A Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by imf09.hostedemail.com (Postfix) with ESMTP id 35040140015 for ; Wed, 7 May 2025 11:05:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=c+V9v308; spf=pass (imf09.hostedemail.com: domain of bhupesh@igalia.com designates 213.97.179.56 as permitted sender) smtp.mailfrom=bhupesh@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746615922; 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=51AuBhOBwcqdxbUaoVuoZuKLaFvWUDOFVfRKxcUsvBc=; b=jvxiJbH9xChliXts3LVJhYPqWN+4LctERozSE7pCKTYLt8bmt/ViSw64JJrLLPXHe86cuJ hIrYHnngxg5g3srkktAlKCTN7gYOvwF9llDVRMwtfcuEeMA67GjiW6Ot5s1e//j5tAiR2W tZy5s9XwH3qXOaGYEDGuZDiHTLFR/wY= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=c+V9v308; spf=pass (imf09.hostedemail.com: domain of bhupesh@igalia.com designates 213.97.179.56 as permitted sender) smtp.mailfrom=bhupesh@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746615922; a=rsa-sha256; cv=none; b=hFT8KQofdou/OraFYynWJlDgvgxxznF6buh8V8ZfcN0CFiLA5W82cjof8L2e+67uwBpGPI lxHAieNMzh8cPiqi8odntV5JrW02n7rhOtlSOXZrNvazvkJQqfsJcqfBDszYly17gz4NSP CaBdA9Hf3vCOGGJUfei+SY9Pk1Bmj04= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=51AuBhOBwcqdxbUaoVuoZuKLaFvWUDOFVfRKxcUsvBc=; b=c+V9v308TdkSpaG+OfUH7HAacT 9/B9haik3YVxK0Ia3scGUjrCntDrNaLtCbHYvRr2HNnjF7DVkLEicy0+dtcxdd2NlxYVC1gLPGtt7 n8ibJh4vHTvLTsjgyF5oXT788+GUY0ltDBPXOAhKweJeJZr5ZYypXBOVik9/+ipxGfij5ozXQoDTK hMwpeT2LSMeUG3TWyYhsjTij331Vx2F16L9PFbz6qLBFUu3Dxk8ClrOAuwC/4x18wvjTy0fpXX2mZ Gy1DeGH7iZnapCCKlVg5ohtDpP3yg6HJgiwRB8pBEwHHxGeHrenrerLHCVQlCVlzz73u92xCeOpdM ZDzBRbYg==; Received: from [223.233.66.62] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uCcWg-004fhg-Ha; Wed, 07 May 2025 13:05:17 +0200 From: Bhupesh To: akpm@linux-foundation.org Cc: bhupesh@igalia.com, kernel-dev@igalia.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, oliver.sang@intel.com, lkp@intel.com, laoar.shao@gmail.com, pmladek@suse.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, alexei.starovoitov@gmail.com, andrii.nakryiko@gmail.com, mirq-linux@rere.qmqm.pl, peterz@infradead.org, willy@infradead.org, david@redhat.com, viro@zeniv.linux.org.uk, keescook@chromium.org, ebiederm@xmission.com, brauner@kernel.org, jack@suse.cz, mingo@redhat.com, juri.lelli@redhat.com, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com Subject: [PATCH v3 3/3] exec: Add support for 64 byte 'tsk->real_comm' Date: Wed, 7 May 2025 16:34:44 +0530 Message-Id: <20250507110444.963779-4-bhupesh@igalia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250507110444.963779-1-bhupesh@igalia.com> References: <20250507110444.963779-1-bhupesh@igalia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 35040140015 X-Stat-Signature: yy9385zxpnr96pw334ajjhq9ko3ikuyp X-HE-Tag: 1746615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7gfWoHvIMr39S+dxcYfnQzdJoK9pGQRxSq2zdbjp9RCHdWEoIh07MqoJdYkdBwSeI/54AmESr4oalYhaPEG+/oflrBNgmhGiwpVFkYad1xwBpA6G+pNSX7RKyCSRDTIbv6Xv9n0An5TqRAaN5xZDel+Vd8R56F+PIlQx94hbq9MdbP7Y8QvShhULyo+yS/W4a2o0DkX9K3gElXY0tn0iF58wyJ3a9+DWaHa45w/TVuIt58DTgkveYwfWRoTStxU4Asf1u3CBrh9ZM3DbjcIZSnlMJA5gYG2+nUfS0KZwj/duaTfFVi5aXnF4jjfNod3Dli09qj8670Ne2InWr/UjTAOtIGl5q4vDnkJsrjTf6kWmcD97f2hMg4wkrGCFdw== 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: Historically due to the 16-byte length of TASK_COMM_LEN, the users of 'tsk->comm' are restricted to use a fixed-size target buffer also of TASK_COMM_LEN for 'memcpy()' like use-cases. To fix the same, Linus suggested in [1] that we can add the following union inside 'task_struct': union { char comm[TASK_COMM_LEN]; char real_comm[REAL_TASK_COMM_LEN]; }; and then modify '__set_task_comm()' to pass 'tsk->real_comm' to the existing users. This would mean that: (1) The old common pattern of just printing with '%s' and tsk->comm would just continue to work (as it is): pr_alert("BUG: Bad page state in process %s pfn:%05lx\n", current->comm, page_to_pfn(page)); (2) And, the memcpy() users of 'tsk->comm' would need to be made more stable by ensuring that the destination buffer always has a closing NUL character (done already in the preceding patch in this series). So, eventually: - users who want the existing 'TASK_COMM_LEN' behavior will get it (existing ABIs would continue to work), - users who just print out 'tsk->comm' as a string will get the longer new "real comm", - users who do 'sizeof(->comm)' will continue to get the old value because of the union. [1]. https://lore.kernel.org/all/CAHk-=wjAmmHUg6vho1KjzQi2=psR30+CogFd4aXrThr2gsiS4g@mail.gmail.com Signed-off-by: Bhupesh --- fs/exec.c | 6 +++--- include/linux/sched.h | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 8e4ea5f1e64c..2b2f2dacc013 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1190,11 +1190,11 @@ static int unshare_sighand(struct task_struct *me) */ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) { - size_t len = min(strlen(buf), sizeof(tsk->comm) - 1); + size_t len = min(strlen(buf), sizeof(tsk->real_comm) - 1); trace_task_rename(tsk, buf); - memcpy(tsk->comm, buf, len); - memset(&tsk->comm[len], 0, sizeof(tsk->comm) - len); + memcpy(tsk->real_comm, buf, len); + memset(&tsk->real_comm[len], 0, sizeof(tsk->real_comm) - len); perf_event_comm(tsk, exec); } diff --git a/include/linux/sched.h b/include/linux/sched.h index cb219c6db179..2744d90badf1 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -317,6 +317,7 @@ struct user_event_mm; */ enum { TASK_COMM_LEN = 16, + REAL_TASK_COMM_LEN = 64, }; extern void sched_tick(void); @@ -1162,7 +1163,10 @@ struct task_struct { * - logic inside set_task_comm() will ensure it is always NUL-terminated and * zero-padded */ - char comm[TASK_COMM_LEN]; + union { + char comm[TASK_COMM_LEN]; + char real_comm[REAL_TASK_COMM_LEN]; + }; struct nameidata *nameidata; @@ -2005,7 +2009,7 @@ extern void __set_task_comm(struct task_struct *tsk, const char *from, bool exec */ #define get_task_comm(buf, tsk) ({ \ BUILD_BUG_ON(sizeof(buf) < TASK_COMM_LEN); \ - strscpy_pad(buf, (tsk)->comm); \ + strscpy_pad(buf, (tsk)->real_comm); \ buf; \ }) -- 2.38.1