From patchwork Mon Nov 1 06:04:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595839 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A817C433FE for ; Mon, 1 Nov 2021 06:04:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CBB456108D for ; Mon, 1 Nov 2021 06:04:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CBB456108D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 694728000E; Mon, 1 Nov 2021 02:04:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61E7780008; Mon, 1 Nov 2021 02:04:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 495E58000E; Mon, 1 Nov 2021 02:04:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id 374BF80008 for ; Mon, 1 Nov 2021 02:04:33 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id F3FAE54715 for ; Mon, 1 Nov 2021 06:04:32 +0000 (UTC) X-FDA: 78759322026.04.A396D0B Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf13.hostedemail.com (Postfix) with ESMTP id 3828D143F637 for ; Mon, 1 Nov 2021 06:04:25 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id o10-20020a17090a3d4a00b001a6555878a8so3786221pjf.1 for ; Sun, 31 Oct 2021 23:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jvb/C5XEaJIeXrLXfpoEk1LkH8WdHTYd7IpTBiq7fdU=; b=QzDoHhHVbtF/bMpHfWbGSlGfWhrLJ3uom/bYNboWDxPau83NZSUbxcsyS3VC0UFwNm IYFWwZxp+p4qvZ5D2tK0osULt9fSRrn39+6+qRP+w8MHRqyPsENAX3Qbce93XloeW0b7 bhZt0u3DwNeykH6ljwHZncNhJdpGAHRDhJ+vIJ5DBB7n6lBWqcVSVnF3oo2IyGW0E2kq JGcTLy1m5V0sKMiuH0G7VtSf8DXS60yNBtgOiW7rsb0a+93/1HmKSOD1N4EI+UEMmIzY d2ig8smuUy3ycMA8HdA6saon+W6X9JZ04Wu2GeG9I6XPzrEbZl3+/fmY4uZ51gpf30GP lfVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jvb/C5XEaJIeXrLXfpoEk1LkH8WdHTYd7IpTBiq7fdU=; b=iJF9rib8kV9fWXWIbtJw+ilXR/tAFPvXvL3egf1ArjKDJ8mbFzenKaAKw54Eg2lzHB aQMwag+RNWlNhXoZBnnMCsWOUo/dCGoORWP/RZRth9RgiG02TOgmXeft8ng/U0EOy/Ce z3hzDlfAFfO6MOmJOtCFbt8Yw2wk1gWFL77jxmZtfQkZBvueDTdwWEBrRLiR0Ld98fK0 S/8t9pZPF+S+dyTj5eU2w8qA9BIwf7ZUOJkY3VMMafeHA7RNKFDCB+LCi3dkpWwo1ZG8 Nd9gEsbkEsrQyBSjA13o4L877x3jp/SADfzJ7FRYWgkKRS9P0Mj3rMY5Zb9bZhqioyli itOA== X-Gm-Message-State: AOAM532W4KinrD6981c7IaaLmx/FoSaehX/FSclFfzn1PdrA2lLqj9ZV DICWhaN9YEw8rqSsypsN4Ws= X-Google-Smtp-Source: ABdhPJz8UISjP4gb7nXyp0XisjyBJXUE5NhjaTe21LGX2ejW8wzAuI9dQOwUx1G/kySMdPO2jta5Ag== X-Received: by 2002:a17:90b:30c6:: with SMTP id hi6mr16797530pjb.201.1635746671810; Sun, 31 Oct 2021 23:04:31 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:31 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 01/11] fs/exec: make __set_task_comm always set a nul terminated string Date: Mon, 1 Nov 2021 06:04:09 +0000 Message-Id: <20211101060419.4682-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3828D143F637 X-Stat-Signature: 9cq61ufdhcdhfnc4owa58oshbmy9pqu7 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QzDoHhHV; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1635746665-852219 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: Make sure the string set to task comm is always nul terminated. Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- fs/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index a098c133d8d7..404156b5b314 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1224,7 +1224,7 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) { task_lock(tsk); trace_task_rename(tsk, buf); - strlcpy(tsk->comm, buf, sizeof(tsk->comm)); + strscpy_pad(tsk->comm, buf, sizeof(tsk->comm)); task_unlock(tsk); perf_event_comm(tsk, exec); } From patchwork Mon Nov 1 06:04:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595841 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87278C433EF for ; Mon, 1 Nov 2021 06:04:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 256FE61078 for ; Mon, 1 Nov 2021 06:04:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 256FE61078 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B037A8000F; Mon, 1 Nov 2021 02:04:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB3E080008; Mon, 1 Nov 2021 02:04:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 903528000F; Mon, 1 Nov 2021 02:04:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id 79EB980008 for ; Mon, 1 Nov 2021 02:04:35 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 33B9032343 for ; Mon, 1 Nov 2021 06:04:35 +0000 (UTC) X-FDA: 78759322068.18.8FC467A Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf18.hostedemail.com (Postfix) with ESMTP id DE3334002091 for ; Mon, 1 Nov 2021 06:04:34 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id k4so1069394plx.8 for ; Sun, 31 Oct 2021 23:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HfuDNEiJT3BfJis8gojDnNsP87rFWM/LtilUesqMR5U=; b=hPb9/J7ocOjTulc4EreHCv8ZMiDH7pY0cCDo/lAIUe0tnuOnhIo5NHHug7nWuJhrNC 6vtVwF5uYsRSCf7RfEpnZD/J0nqa25t6NpDZ053/nVgcg1n+PRqGI40eSjB5C9FL96df 4D6KcJrwmQXgwdK4zJJfcYP3RS9yKvQgt8/ZkbbVP3+ilc93odwkhmd3O0NAarTD5WDq ZnoJsc4bZN1D3V6Fo82j0RR5+FKeHn+QsNLQHdHfs84ZO8yuGicC3Jn5/yvYglIqpHXU 8obAblxVypVdciBUpGDBoPUuxBiOWFZ1wv+VfYR44yyHma+mcUd73KOAlrLzu1v57TYJ aR1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HfuDNEiJT3BfJis8gojDnNsP87rFWM/LtilUesqMR5U=; b=GfI8/lgqNHT1esVmQOXyz+GZRXznOhdcXJMIYNmKN9HlhVySanrLEhOnE1MSdTeeRo zEbpl7tMXIb7BBEdQeGdXJG3p7EOKo7nniC4dpZrzVhZmkvQCxb4YyamJRHYF18LnOli n3GGaSpGlTh/VDMgy3k4G3VT01H3P7j9sDlQJNxgvsA1dM0pn6/eZQMvTWq5gU1NL9fm T1GYQ97Z5SzXOxnyTIJ90Z2DrULRPvawjYetgcE11T9k+WkFE0D2ipCShOrmTD0w5kNU Si1yKWPTfh8dh+ef19pZwZTE86HslZrGLUQhB5waK/9ArSaKQ+6RALHjzkIR/5VXyl1H uotg== X-Gm-Message-State: AOAM532knzoefn+C3NuTfgT+v8AqCR+/AjKRjk+z6JKCn4HTjCzeF9aG 67+I2idAvCyVvMF53W/sVWA= X-Google-Smtp-Source: ABdhPJzGByODALzastMQt6vIF+ynjmZShKqwIA1uQ394MFzxHKuVJACVDnLYpsoO/05vk972q4vbYA== X-Received: by 2002:a17:90b:30e:: with SMTP id ay14mr15464050pjb.60.1635746674092; Sun, 31 Oct 2021 23:04:34 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:33 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 02/11] fs/exec: make __get_task_comm always get a nul terminated string Date: Mon, 1 Nov 2021 06:04:10 +0000 Message-Id: <20211101060419.4682-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DE3334002091 X-Stat-Signature: drdm7zd4wzejkzt8ksaob5kq8t6xrbe5 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="hPb9/J7o"; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1635746674-507287 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: If the dest buffer size is smaller than sizeof(tsk->comm), the buffer will be without null ternimator, that may cause problem. We can make sure the buffer size not smaller than comm at the callsite to avoid that problem, but there may be callsite that we can't easily change. Using strscpy_pad() instead of strncpy() in __get_task_comm() can make the string always nul ternimated. Suggested-by: Kees Cook Suggested-by: Steven Rostedt Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- fs/exec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index 404156b5b314..013b707d995d 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1209,7 +1209,8 @@ static int unshare_sighand(struct task_struct *me) char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk) { task_lock(tsk); - strncpy(buf, tsk->comm, buf_size); + /* Always NUL terminated and zero-padded */ + strscpy_pad(buf, tsk->comm, buf_size); task_unlock(tsk); return buf; } From patchwork Mon Nov 1 06:04:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595843 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AEB9C4167B for ; Mon, 1 Nov 2021 06:04:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 921846108F for ; Mon, 1 Nov 2021 06:04:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 921846108F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 24E5080010; Mon, 1 Nov 2021 02:04:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D8E180008; Mon, 1 Nov 2021 02:04:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0534D80010; Mon, 1 Nov 2021 02:04:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id E45AB80008 for ; Mon, 1 Nov 2021 02:04:37 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9D5B1181892E6 for ; Mon, 1 Nov 2021 06:04:37 +0000 (UTC) X-FDA: 78759322236.17.84F24F2 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf18.hostedemail.com (Postfix) with ESMTP id 5404C4002091 for ; Mon, 1 Nov 2021 06:04:37 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id np3so1180941pjb.4 for ; Sun, 31 Oct 2021 23:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rZRlybNT1VQOoNxdQue8vo9tAC5dSJmDk+dmEknNUrc=; b=a1M395Bqh+HLw+RAGcbuG3Ee9gQ5Pt14RuYZaJHZtAq8IsesqFhaR4qs895G5hbMKL iQS5vYZGfgH7a5b3h4KU8iCUQfcJ2pMAUZ7xUYJlwNlcv/9R98mCr+O99gLbYNgvnTdf Jq1Q2Y9+75eoLINoepcqswMcLPx+E9zUvTqyDgQoDj1JjQ7GhueGgF6r1EyHzZ4+n1+P 4VyRgUsHzVN0JaYnojDA5tc4RqapLPK5V8yI7l8aREDyn7EoVRQ484iSc2Ox4D6ZVWo3 RXydvoGhJx9s1/xKjIdOKtfqIsQHqS0jolmiHdBqkJBvY53eM6lKKs8AgkFuHiKGjnlr HK4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rZRlybNT1VQOoNxdQue8vo9tAC5dSJmDk+dmEknNUrc=; b=N4mDdWgEym+NvoahZ6Df32QTnmuxuOZAVETIH5qjIFZ2sgFxsFbh+wvOw44tiRGoIE o90NxnistVIgmWLtOT/hOkUjpI7tDHwhywNg2Mv/UQjST9ClPc4zv3IYP+iBhYKjBfuj C4UYtt/3MhvUfKOQgCoHgkcdVYZve0I+6MgYnOKrR3MElnpTMumYAJKq2/nifNnq2R0O KRRh/R3xJAObtE8sgYXYwqqR3ReK1/YNYTaTmWAeEW7V/pC2T68b+1JZioRoBDGj90vG J+Mv5OfzfHDlEK4YeC0b0vgHpNnVXA0k7ZL3BRhK7A7Fezpg/1tWjwyVsLwSMkyOkXC7 kdCQ== X-Gm-Message-State: AOAM5306El3iZ0WNby4m3pT679kUmvJD7+otYkY+bhPlheEjMx7veGjz 3N1N8x04TVtb4xMebDHRgl8= X-Google-Smtp-Source: ABdhPJzL4jPx+ZhAWUkFzp5hvgKpDWtgYKzpi4hD6dRWbzMDiPGRwPGbJb/YNiUpFAuwRHKj4szYdg== X-Received: by 2002:a17:902:8bcb:b0:141:b34e:d54f with SMTP id r11-20020a1709028bcb00b00141b34ed54fmr15789414plo.68.1635746676451; Sun, 31 Oct 2021 23:04:36 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:35 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 03/11] sched.h: use __must_be_array instead of BUILD_BUG_ON in get_task_comm Date: Mon, 1 Nov 2021 06:04:11 +0000 Message-Id: <20211101060419.4682-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=a1M395Bq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-Stat-Signature: hkytanee1an5rtbbo3kgqn7a7g6qxrrg X-Rspamd-Queue-Id: 5404C4002091 X-Rspamd-Server: rspam01 X-HE-Tag: 1635746677-618890 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: Now that __get_task_comm() will truncate and pad, it's safe to use on both too-small and too-big arrays. So it is not needed to check array length any more. For the original goal of making sure get_task_comm() is being used on a char array, we can use __must_be_array(). Below is the verification when I changed the dest buffer of get_task_comm() in a driver code, CC [M] drivers/infiniband/hw/qib/qib_file_ops.o In file included from ./include/linux/bits.h:22:0, from ./include/linux/ioport.h:13, from ./include/linux/pci.h:31, from drivers/infiniband/hw/qib/qib_file_ops.c:35: drivers/infiniband/hw/qib/qib_file_ops.c: In function ‘setup_ctxt’: ./include/linux/build_bug.h:16:51: error: negative width in bit-field ‘’ #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) ^ ./include/linux/compiler.h:258:28: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’ #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) ^~~~~~~~~~~~~~~~~ ./include/linux/sched.h:1941:23: note: in expansion of macro ‘__must_be_array’ __get_task_comm(buf, __must_be_array(buf) + sizeof(buf), tsk) ^~~~~~~~~~~~~~~ drivers/infiniband/hw/qib/qib_file_ops.c:1325:2: note: in expansion of macro ‘get_task_comm’ get_task_comm(test, current); It hit this warnig as expected. Suggested-by: Kees Cook Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- include/linux/sched.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index c1a927ddec64..b9c85c52fed0 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1931,10 +1931,8 @@ static inline void set_task_comm(struct task_struct *tsk, const char *from) } extern char *__get_task_comm(char *to, size_t len, struct task_struct *tsk); -#define get_task_comm(buf, tsk) ({ \ - BUILD_BUG_ON(sizeof(buf) != TASK_COMM_LEN); \ - __get_task_comm(buf, sizeof(buf), tsk); \ -}) +#define get_task_comm(buf, tsk) \ + __get_task_comm(buf, __must_be_array(buf) + sizeof(buf), tsk) #ifdef CONFIG_SMP static __always_inline void scheduler_ipi(void) From patchwork Mon Nov 1 06:04:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595845 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B220C433EF for ; Mon, 1 Nov 2021 06:04:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D0A846108D for ; Mon, 1 Nov 2021 06:04:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D0A846108D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6BA7B80011; Mon, 1 Nov 2021 02:04:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 691FC80008; Mon, 1 Nov 2021 02:04:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50B7A80011; Mon, 1 Nov 2021 02:04:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 3CCFD80008 for ; Mon, 1 Nov 2021 02:04:41 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2B66A182057E9 for ; Mon, 1 Nov 2021 06:04:40 +0000 (UTC) X-FDA: 78759322362.17.0624911 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf24.hostedemail.com (Postfix) with ESMTP id B75C1B00009F for ; Mon, 1 Nov 2021 06:04:39 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id y20so4630863pfi.4 for ; Sun, 31 Oct 2021 23:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o3r423UmuBw5jHyHMAFihSOkgDAeE6bhihnHvX68874=; b=LMNo4W3TjV5llf6jnlGy9NTRwR+hoKt0QLv5GmrPdv3tnhWv9SWc7CJ7IPQ25LBnzk bcRtJNIrFLRYdb+nwHDIMCzxk8OcTqZj1+KQoDpEpEyi4CNOYzHG7irT+iMD/qus1bRP gJpNr3rEp+9oEiUuNaizI1x0DMWAc3vLy2WnsYbX1+wB63+hqz8QVD8LDeRx0SgfgqKw 29ejtUEHKc/vPJ8SAql+Fv/wLIFhF7PSo8w1Ydn9qX+mHD0mR9MnwZ+am4lPfe/PBi3u mJbBqphRMOFBQ/gfkyGl+Ss6tcUTIXKBTaH7ednulSWrpVWbdBFxaDEy0u77cY4ekOZz EDRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o3r423UmuBw5jHyHMAFihSOkgDAeE6bhihnHvX68874=; b=nzYtb6MkDrkGwLajWpf17ovo7lSgKHM8h7knuoEBghZQvcD9h4z9J5/TchW9N/FFZb N5SqQX64SNURMGTy7bkTV23bLZy9mEyFGwrNKjoMfmVFaUcncmZtqlI3DSebJNo4C6cV nifs8Mttni5lXNQGheMzcg/BvTbp1+YecCwjMHgSyBMIc56agCJtcSdoImyNQj0+3ad/ BEmFti21Ba4WaKFS51KPu16AKhFA1mI6M7fVr25rDFiYH8yv5XPYiMZqFykWdTKnVrIF VajP5Ik29bUdeLtqeRGp8VtBkFmTEm8f0UmHkr+4/tTimw7nJWAcqZDbLBGg3vZLmjlj TmOA== X-Gm-Message-State: AOAM530MmfTuDK4kBeDcG9+VlUH0WJFIK/Q+UPJO5AKKjIRtIaBI4k7P BLKUP4UJ/wlOpyr3W0yXek0= X-Google-Smtp-Source: ABdhPJxaybbOZX2waEJCer7qTNlHbiwvvo3L2vD0OkVD9dD70R5sF0i0k+8R93jpwPu6/vpMsOcejw== X-Received: by 2002:a05:6a00:2311:b0:431:c19f:2a93 with SMTP id h17-20020a056a00231100b00431c19f2a93mr26982527pfh.11.1635746678877; Sun, 31 Oct 2021 23:04:38 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:38 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 04/11] drivers/infiniband: make setup_ctxt always get a nul terminated task comm Date: Mon, 1 Nov 2021 06:04:12 +0000 Message-Id: <20211101060419.4682-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B75C1B00009F X-Stat-Signature: yy556hwwjkuehrdqes3tczn3ng4bqxtm Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LMNo4W3T; spf=pass (imf24.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1635746679-350629 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: Use get_task_comm() instead of open-coded strlcpy() to make the comm always nul terminated. As the comment above the hard-coded 16, we can replace it with TASK_COMM_LEN, then it will adopt to the comm size change. Signed-off-by: Yafang Shao Acked-by: Dennis Dalessandro Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- drivers/infiniband/hw/qib/qib.h | 2 +- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h index 9363bccfc6e7..a8e1c30c370f 100644 --- a/drivers/infiniband/hw/qib/qib.h +++ b/drivers/infiniband/hw/qib/qib.h @@ -196,7 +196,7 @@ struct qib_ctxtdata { pid_t pid; pid_t subpid[QLOGIC_IB_MAX_SUBCTXT]; /* same size as task_struct .comm[], command that opened context */ - char comm[16]; + char comm[TASK_COMM_LEN]; /* pkeys set by this use of this ctxt */ u16 pkeys[4]; /* so file ops can get at unit */ diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c index 63854f4b6524..aa290928cf96 100644 --- a/drivers/infiniband/hw/qib/qib_file_ops.c +++ b/drivers/infiniband/hw/qib/qib_file_ops.c @@ -1321,7 +1321,7 @@ static int setup_ctxt(struct qib_pportdata *ppd, int ctxt, rcd->tid_pg_list = ptmp; rcd->pid = current->pid; init_waitqueue_head(&dd->rcd[ctxt]->wait); - strlcpy(rcd->comm, current->comm, sizeof(rcd->comm)); + get_task_comm(rcd->comm, current); ctxt_fp(fp) = rcd; qib_stats.sps_ctxts++; dd->freectxts--; From patchwork Mon Nov 1 06:04:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595847 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98DC7C433FE for ; Mon, 1 Nov 2021 06:04:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D13B60EBC for ; Mon, 1 Nov 2021 06:04:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4D13B60EBC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C893A80012; Mon, 1 Nov 2021 02:04:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C10C580008; Mon, 1 Nov 2021 02:04:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A646680012; Mon, 1 Nov 2021 02:04:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id 8E70980008 for ; Mon, 1 Nov 2021 02:04:42 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 49D973A7DE for ; Mon, 1 Nov 2021 06:04:42 +0000 (UTC) X-FDA: 78759322362.18.21192C3 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf17.hostedemail.com (Postfix) with ESMTP id EC5EAF000393 for ; Mon, 1 Nov 2021 06:04:41 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id f5so16265335pgc.12 for ; Sun, 31 Oct 2021 23:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ap2gAMjIVTbmjeLM5LRGgC4luOpifeHIYUs0krjMvxk=; b=Xww3fwhQ6GVEpXF7vRbHR0oD+u34jHMA9vEJrrh55zmht9IdE5Qb/0vjbQs4HN5gvY POcNuU5T+abx6eRSGb9nZuGqjMlnYzI3jqvFYBpqbT6poqQDzWL/OCelJl7Ho3Jrf54u 5YN/78Tr6wNXbUZYW94XoWas9EC868iRRB80bXY8hf7ZBFghg6/WFfP5WyJZQXRoDLAc 5qWLDy0anYrl3w8SOS4VT5/w0N/L80lgTsNBBnkKg70ESOn1Peuixzj+ADfGsxOt+hYL hcPflq3MyEUgj2IPSiAxx5uysxJUuGk+9g1qy+Fnllx7jZ0Mylv4WfpxvfDZiclIXnpB nNMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ap2gAMjIVTbmjeLM5LRGgC4luOpifeHIYUs0krjMvxk=; b=q4C3aoLNLHq3Do1ddb8F3/Rggy/Dm0a1/I9SZhlycZLTOHztNNy4RZoOIN0Up7hmLn bRsnRl0DG1PD21FDgTPcpcSRskjinqybshziX0Y+WJRWdLcpfia5m/BRIqq6+WXiq6Os FUf7iSBcTKdqyWoMNJRe1n/A1+cMszZU3BV+A4kyRxAGNgRsyXbgWT1N1LHU8ID5ZtSN EKSN9mnBEb/nFmkgwoBDxRlJzQ75M1LjQ/2jjwFYI+KBUimzi4OOYP1iFu+FgnAbB7Z2 wqDFRQXYi1k29MR0Q6LTnJULWYILpsMuoIjR6YAXtLIV8DKyhweATw/NHe7fQnfaAxW/ hTUg== X-Gm-Message-State: AOAM530dl1FVYx8af5Ao8fIjoa1dRqN8BNuLreh5yDrxqwd5vi7gVqVf XtePi+xkXW+QVkCsroub/+Q= X-Google-Smtp-Source: ABdhPJzKLE+vunSqJAXuq5W8qJV8bLajJd/LjCll+mqrJULVSs7WJNF0By6dsSaTkrqw5K5k4BauhA== X-Received: by 2002:a62:1743:0:b0:480:a01f:bf14 with SMTP id 64-20020a621743000000b00480a01fbf14mr11691513pfx.72.1635746681116; Sun, 31 Oct 2021 23:04:41 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:40 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v7 05/11] fs/binfmt_elf: make prpsinfo always get a nul terminated task comm Date: Mon, 1 Nov 2021 06:04:13 +0000 Message-Id: <20211101060419.4682-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Xww3fwhQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-Stat-Signature: 94iy56xfp58emug8x7e93uq43bujn3fp X-Rspamd-Queue-Id: EC5EAF000393 X-Rspamd-Server: rspam01 X-HE-Tag: 1635746681-107167 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: kernel test robot reported a -Wstringop-truncation warning after I extend task comm from 16 to 24. Below is the detailed warning: fs/binfmt_elf.c: In function 'fill_psinfo.isra': >> fs/binfmt_elf.c:1575:9: warning: 'strncpy' output may be truncated copying 16 bytes from a string of length 23 [-Wstringop-truncation] 1575 | strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Replacing the open-coded strncpy() with the helper get_task_comm() can avoid this warning. As the struct prpsinfo is externally parsed, for example by the crash utility, we can't change the size of pr_fname. So I just leave it as-is. I also verfied if it still work well when I extend the comm size to 24. struct elf_prpsinfo is used to dump the task information in userspace coredump or kernel vmcore. Below is the verfication of vmcore, crash> ps PID PPID CPU TASK ST %MEM VSZ RSS COMM 0 0 0 ffffffff9d21a940 RU 0.0 0 0 [swapper/0] > 0 0 1 ffffa09e40f85e80 RU 0.0 0 0 [swapper/1] > 0 0 2 ffffa09e40f81f80 RU 0.0 0 0 [swapper/2] > 0 0 3 ffffa09e40f83f00 RU 0.0 0 0 [swapper/3] > 0 0 4 ffffa09e40f80000 RU 0.0 0 0 [swapper/4] > 0 0 5 ffffa09e40f89f80 RU 0.0 0 0 [swapper/5] 0 0 6 ffffa09e40f8bf00 RU 0.0 0 0 [swapper/6] > 0 0 7 ffffa09e40f88000 RU 0.0 0 0 [swapper/7] > 0 0 8 ffffa09e40f8de80 RU 0.0 0 0 [swapper/8] > 0 0 9 ffffa09e40f95e80 RU 0.0 0 0 [swapper/9] > 0 0 10 ffffa09e40f91f80 RU 0.0 0 0 [swapper/10] > 0 0 11 ffffa09e40f93f00 RU 0.0 0 0 [swapper/11] > 0 0 12 ffffa09e40f90000 RU 0.0 0 0 [swapper/12] > 0 0 13 ffffa09e40f9bf00 RU 0.0 0 0 [swapper/13] > 0 0 14 ffffa09e40f98000 RU 0.0 0 0 [swapper/14] > 0 0 15 ffffa09e40f9de80 RU 0.0 0 0 [swapper/15] It works well as expected. Reported-by: kernel test robot Suggested-by: Kees Cook Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- fs/binfmt_elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index a813b70f594e..138956fd4a88 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1572,7 +1572,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p, SET_UID(psinfo->pr_uid, from_kuid_munged(cred->user_ns, cred->uid)); SET_GID(psinfo->pr_gid, from_kgid_munged(cred->user_ns, cred->gid)); rcu_read_unlock(); - strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname)); + get_task_comm(psinfo->pr_fname, p); return 0; } From patchwork Mon Nov 1 06:04:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595849 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE3B8C433F5 for ; Mon, 1 Nov 2021 06:04:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9F23661078 for ; Mon, 1 Nov 2021 06:04:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9F23661078 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3890280014; Mon, 1 Nov 2021 02:04:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3380980008; Mon, 1 Nov 2021 02:04:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 189C280014; Mon, 1 Nov 2021 02:04:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 0418E80008 for ; Mon, 1 Nov 2021 02:04:45 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B461318020312 for ; Mon, 1 Nov 2021 06:04:44 +0000 (UTC) X-FDA: 78759322488.31.410D844 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf09.hostedemail.com (Postfix) with ESMTP id 62295300010C for ; Mon, 1 Nov 2021 06:04:44 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id x5so6504527pgk.11 for ; Sun, 31 Oct 2021 23:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CZbW1Aleg8hcQ6oriKfCOVzwEMQjjmsZLoOFChfxiOE=; b=hLIVcr6CSGMn7q+duUxCWW0eGrpmQBAmB6Wq4FCLbLyQvr2Upd8TZDDWhXwETwIru5 gVsFVTteDomWNPaucmxRqkCCuS8WRWbKXTXFS4O738YFeGYfE7jLWgBhWcP5Wyl3Ixx1 e9YODtfNTOnD4iIYhMk9WCAiID1UqwO6uuIqcXKNmu7EhFjFVJ/VFfeT8r6Dr1npBbY7 zyuY/z7kwCaKGMOzNmsXif+LtjafxWuoctWRkorVboIJqLwC2HTMPIEGJO5cyPXEJAeh sgohILu4rfKSjNpvEjhK4xvo6H+wsmaaOY6Ipo4srFpfRbzLHJNYJVKU90aLM7DlOEJ/ 4Qrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CZbW1Aleg8hcQ6oriKfCOVzwEMQjjmsZLoOFChfxiOE=; b=bf7XY5LMDGaS4kUFAGqvlutrmZQ2SpZ6lhULa3PC542KPV0JaYQxZTkldRRy4c/397 vVgSeTxzlj3WAu0PQ0ph7jZambc5H4YDYVPCzvOzqQa2xLb8+RML7adGyimUPrGIk8m8 +a5NPOOU0pNrxbLf5UV2UoAYDqLmlDKPyOXcdjtMzkCX036pWDx0ja6NbZO6g2NUOwv4 IDTqiW0WXjRA5PFtFvSaiKthFkWqGd478OeGAyxJT4VK+xnUk2tUiRFZ80XnxPbGKQaL HLldFPH/WBSsSHM7IuxDMIisIOsIzFyrqoQ+5/qUazqiygRj2G89H4+mK3FOghHfMPDT SEIg== X-Gm-Message-State: AOAM533a5G1r3nhLuOElqfJ4QBhOE3ACEEDxWqtQz2KFXuUQkaC8HPxX A/0xpuSfB7EjO3MnlRR0B+E= X-Google-Smtp-Source: ABdhPJy5ahFUxXTC3lwrjdq2rffkJFK0bqTnEW/fg2sOG/fpUs8BcRn22EW5Z/8v2ha5HNBZ374p9Q== X-Received: by 2002:a62:e510:0:b0:44c:e06e:80dd with SMTP id n16-20020a62e510000000b0044ce06e80ddmr27033507pff.48.1635746683498; Sun, 31 Oct 2021 23:04:43 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:43 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 06/11] samples/bpf/test_overhead_kprobe_kern: make it adopt to task comm size change Date: Mon, 1 Nov 2021 06:04:14 +0000 Message-Id: <20211101060419.4682-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 62295300010C X-Stat-Signature: 1ugw6a43cnknt847nnzedc8cju6jurao Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hLIVcr6C; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1635746684-346473 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: bpf_probe_read_kernel_str() will add a nul terminator to the dst, then we don't care about if the dst size is big enough. This patch also replaces the hard-coded 16 with TASK_COMM_LEN to make it adopt to task comm size change. Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- samples/bpf/offwaketime_kern.c | 4 ++-- samples/bpf/test_overhead_kprobe_kern.c | 11 ++++++----- samples/bpf/test_overhead_tp_kern.c | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime_kern.c index 4866afd054da..eb4d94742e6b 100644 --- a/samples/bpf/offwaketime_kern.c +++ b/samples/bpf/offwaketime_kern.c @@ -113,11 +113,11 @@ static inline int update_counts(void *ctx, u32 pid, u64 delta) /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ struct sched_switch_args { unsigned long long pad; - char prev_comm[16]; + char prev_comm[TASK_COMM_LEN]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN]; int next_pid; int next_prio; }; diff --git a/samples/bpf/test_overhead_kprobe_kern.c b/samples/bpf/test_overhead_kprobe_kern.c index f6d593e47037..8fdd2c9c56b2 100644 --- a/samples/bpf/test_overhead_kprobe_kern.c +++ b/samples/bpf/test_overhead_kprobe_kern.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -22,17 +23,17 @@ int prog(struct pt_regs *ctx) { struct signal_struct *signal; struct task_struct *tsk; - char oldcomm[16] = {}; - char newcomm[16] = {}; + char oldcomm[TASK_COMM_LEN] = {}; + char newcomm[TASK_COMM_LEN] = {}; u16 oom_score_adj; u32 pid; tsk = (void *)PT_REGS_PARM1(ctx); pid = _(tsk->pid); - bpf_probe_read_kernel(oldcomm, sizeof(oldcomm), &tsk->comm); - bpf_probe_read_kernel(newcomm, sizeof(newcomm), - (void *)PT_REGS_PARM2(ctx)); + bpf_probe_read_kernel_str(oldcomm, sizeof(oldcomm), &tsk->comm); + bpf_probe_read_kernel_str(newcomm, sizeof(newcomm), + (void *)PT_REGS_PARM2(ctx)); signal = _(tsk->signal); oom_score_adj = _(signal->oom_score_adj); return 0; diff --git a/samples/bpf/test_overhead_tp_kern.c b/samples/bpf/test_overhead_tp_kern.c index eaa32693f8fc..80edadacb692 100644 --- a/samples/bpf/test_overhead_tp_kern.c +++ b/samples/bpf/test_overhead_tp_kern.c @@ -4,6 +4,7 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ +#include #include #include @@ -11,8 +12,8 @@ struct task_rename { __u64 pad; __u32 pid; - char oldcomm[16]; - char newcomm[16]; + char oldcomm[TASK_COMM_LEN]; + char newcomm[TASK_COMM_LEN]; __u16 oom_score_adj; }; SEC("tracepoint/task/task_rename") From patchwork Mon Nov 1 06:04:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595851 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DC56C4332F for ; Mon, 1 Nov 2021 06:04:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E44F360EBC for ; Mon, 1 Nov 2021 06:04:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E44F360EBC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 81B0E80015; Mon, 1 Nov 2021 02:04:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77FFB80008; Mon, 1 Nov 2021 02:04:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50C3380015; Mon, 1 Nov 2021 02:04:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 3681D80008 for ; Mon, 1 Nov 2021 02:04:47 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EE6043A7DE for ; Mon, 1 Nov 2021 06:04:46 +0000 (UTC) X-FDA: 78759322572.13.740AB66 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf08.hostedemail.com (Postfix) with ESMTP id 0AB3D3000098 for ; Mon, 1 Nov 2021 06:04:36 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id n18so10897995plc.2 for ; Sun, 31 Oct 2021 23:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UnbvpW9WGZPPHsD461H5NLpgI+BcZRpk9Uvkg/7/FsI=; b=mBgEqR2cuqWgG4wbE+Ee9nl7PI0oPuF//CHOFEk3rqDKH5Wv+2P8q+SgcLACl7Eu1S DYIBVewqg0Hdo0Z9cjB8Sc4otEiDDpzHVGJDzdQm/23So6LaXX9kNiFXBxpugZ7V+xVS 0csKWuVOGikNjqyzPgk+VenqX+qZTV7bDJrecXDWyeYudRBWBkdXOMGaT3EtG6yamLnt oT+8TiedZHp3qG2ml51vaYf8orZUmG0H45pcDpUssVRSPBh7l6VY8IyPdChDJul82kv5 Ev7EY/jQQfLSgW8XNit4lnKgN4T8Rq4bUuBwJvyrwIhPyecKtKCfMJM4hdXsmzwSwxCL KqcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UnbvpW9WGZPPHsD461H5NLpgI+BcZRpk9Uvkg/7/FsI=; b=IELWHkEYDPHK5+r1g27avHxXqdDU02+cdvyZfsHJXQsuYewOghVwfIQBqIJwXvnYFg MOOnyWGrj0UiCrlqOpMySF23jla3fmNkpfjI9+SXCozJaNOsm2DyLFrXCAkF7scu+6yB ygpaWgfClyIek22uPK0/sKctxduvpdvAzm3yZAKJPnKnn/sRL1i+js9B8Cl2WClg6nNF g3PAf/Ypkclz56MzNArcQHjAwLdlX1AS8w3JepqpU9Z0pq20FGM/OQ9aglE4Qgr+C28o vEacv/qM5YZX+9gkVJzr2tmX6hYpbkls++4GK9WlMUWAo9V23g+n8CSoBFPSqi+9LRYk hvJw== X-Gm-Message-State: AOAM533qAvC+KCK/5jRLYeiV73lmOdewSxfTJlO9Xi2PUUfFbuT6P+V2 CxQMeuC8jBJVC6/4aW1LMlI= X-Google-Smtp-Source: ABdhPJzGCvt5iEpyM474KY6O62Zlsfcvpf7wrXcYqDsBGf7Az/ne89nFa22e0UxYm86jwgxdTn2BTA== X-Received: by 2002:a17:902:bd01:b0:141:6232:6f89 with SMTP id p1-20020a170902bd0100b0014162326f89mr23251730pls.12.1635746685828; Sun, 31 Oct 2021 23:04:45 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:45 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 07/11] tools/bpf/bpftool/skeleton: make it adopt to task comm size change Date: Mon, 1 Nov 2021 06:04:15 +0000 Message-Id: <20211101060419.4682-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0AB3D3000098 X-Stat-Signature: pki9megbj94yyrmi5uch4seygot1pju6 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mBgEqR2c; spf=pass (imf08.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1635746676-377356 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: bpf_probe_read_kernel_str() will add a nul terminator to the dst, then we don't care about if the dst size is big enough. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek Acked-by: Andrii Nakryiko --- tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c index d9b420972934..f70702fcb224 100644 --- a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c +++ b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c @@ -71,8 +71,8 @@ int iter(struct bpf_iter__task_file *ctx) e.pid = task->tgid; e.id = get_obj_id(file->private_data, obj_type); - bpf_probe_read_kernel(&e.comm, sizeof(e.comm), - task->group_leader->comm); + bpf_probe_read_kernel_str(&e.comm, sizeof(e.comm), + task->group_leader->comm); bpf_seq_write(ctx->meta->seq, &e, sizeof(e)); return 0; From patchwork Mon Nov 1 06:04:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595853 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72536C433EF for ; Mon, 1 Nov 2021 06:04:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2939060EBC for ; Mon, 1 Nov 2021 06:04:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2939060EBC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B4EA480016; Mon, 1 Nov 2021 02:04:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD83C80008; Mon, 1 Nov 2021 02:04:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DF6680016; Mon, 1 Nov 2021 02:04:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id 7765780008 for ; Mon, 1 Nov 2021 02:04:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 379153A7DE for ; Mon, 1 Nov 2021 06:04:49 +0000 (UTC) X-FDA: 78759322740.05.DFFFBA5 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf10.hostedemail.com (Postfix) with ESMTP id 6EE576001991 for ; Mon, 1 Nov 2021 06:04:39 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id 75so16328316pga.3 for ; Sun, 31 Oct 2021 23:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2AOLQynizUK/9ub+MV3+x/PqsjWBik6Y2qklqSq5kvM=; b=l0EIvzonzcNlCGT6TjXsysXA3uAstk65U4vdn7q433mY6i9VaZO0ffvw4f0T7ELy+H v5u+ZBM7SAyqPzYBN8O3x3hA2xIUlUhwyCu+BC5V53HvycjI8Hi1umyK7IQJacmk7i6o khFyYXCW5nWroZrXjJsWFekl96dq67dFeaypF802J/p4iwuZyg6Sdmu4rhSJT2qJi5Xn 00XpVbToRKPbkrTugqQahtpW6uED5b5mo1TqnqCLLEU/0vh43M+JEmJ14r4WejDOBaEu +jeAFO9mXb76Vk4n5De0pRxb2KCQFi3+BU1G2dJDHO+QI+K2i7tRGETK7bbMtOtDZjJV Xahg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2AOLQynizUK/9ub+MV3+x/PqsjWBik6Y2qklqSq5kvM=; b=g1zP1E8b54jpHKMS99lOmc66UHdW0gvjLEhDiu1D1BhbTbJF+N4Nmc6NNfrChfu8+C 5Ngb7erXcgsJmFgNEHgyX2QcjcDXPXzyJOgdsnUHK2oVN+MnJs64JvwCrWAgxAVKCekJ VBnfFVHVOaowvSiiGD/D9Cmdh2NG95wa8SVia/D2m8/PoeCxfcjgqSccHVi2eYx8fxou GPVIXJBNmY1TiLXOrkL+XBBc5C/d2Sy+KO5a9PkXqpt9Bpx+5nb3E8ZwiSVTmJRo4G6E OhvqtMF8+dUByIHv7YzhP0+S9Px0dEe3GcFmFFshSyLqAc6oWyIdgXAA4qazEJPOqoM/ jYYg== X-Gm-Message-State: AOAM532YTwkY7tR23SLDCBWqvsvcMF4UWdOEoAAmuwlZOCMAd8OoDMdM ZEgfPxDxqsNp4VtQ7GR67aA= X-Google-Smtp-Source: ABdhPJyam8xih1Z6tKYYGpuiGMnnmxuj4/L4ZJpVlE3q5S3rpYWdBTOmUb41H+/yZOg+DA2kjkENOw== X-Received: by 2002:a63:8f4a:: with SMTP id r10mr20105733pgn.337.1635746688077; Sun, 31 Oct 2021 23:04:48 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:47 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 08/11] tools/perf/test: make perf test adopt to task comm size change Date: Mon, 1 Nov 2021 06:04:16 +0000 Message-Id: <20211101060419.4682-9-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6EE576001991 X-Stat-Signature: ti3mag1tg4ef8qwgsto3hs4yehxyxxs8 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=l0EIvzon; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-HE-Tag: 1635746679-45638 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: kernel test robot reported a perf-test failure after I extended task comm size from 16 to 24. The failure as follows, 2021-10-13 18:00:46 sudo /usr/src/perf_selftests-x86_64-rhel-8.3-317419b91ef4eff4e2f046088201e4dc4065caa0/tools/perf/perf test 15 15: Parse sched tracepoints fields : FAILED! The reason is perf-test requires a fixed-size task comm. If we extend task comm size to 24, it will not equil with the required size 16 in perf test. After some analyzation, I found perf itself can adopt to the size change, for example, below is the output of perf-sched after I extend comm size to 24 - task 614 ( kthreadd: 84), nr_events: 1 task 615 ( systemd: 843), nr_events: 1 task 616 ( networkd-dispat: 1026), nr_events: 1 task 617 ( systemd: 846), nr_events: 1 $ cat /proc/843/comm networkd-dispatcher The task comm can be displayed correctly as expected. Replace old hard-coded 16 with the new one can fix the warning, but we'd better make the test accept both old and new sizes, then it can be backward compatibility. After this patch, the perf-test succeeds no matter task comm is 16 or 24 - 15: Parse sched tracepoints fields : Ok This patch is a preparation for the followup patch. Reported-by: kernel test robot Suggested-by: Arnaldo Carvalho de Melo Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- tools/include/linux/sched.h | 11 +++++++++++ tools/perf/tests/evsel-tp-sched.c | 26 ++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 tools/include/linux/sched.h diff --git a/tools/include/linux/sched.h b/tools/include/linux/sched.h new file mode 100644 index 000000000000..0d575afd7f43 --- /dev/null +++ b/tools/include/linux/sched.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_SCHED_H +#define _TOOLS_LINUX_SCHED_H + +/* Keep both length for backward compatibility */ +enum { + TASK_COMM_LEN_16 = 16, + TASK_COMM_LEN = 24, +}; + +#endif /* _TOOLS_LINUX_SCHED_H */ diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c index f9e34bd26cf3..029f2a8c8e51 100644 --- a/tools/perf/tests/evsel-tp-sched.c +++ b/tools/perf/tests/evsel-tp-sched.c @@ -1,11 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include "evsel.h" #include "tests.h" #include "debug.h" -static int evsel__test_field(struct evsel *evsel, const char *name, int size, bool should_be_signed) +static int evsel__test_field_alt(struct evsel *evsel, const char *name, + int size, int alternate_size, bool should_be_signed) { struct tep_format_field *field = evsel__field(evsel, name); int is_signed; @@ -23,15 +25,24 @@ static int evsel__test_field(struct evsel *evsel, const char *name, int size, bo ret = -1; } - if (field->size != size) { - pr_debug("%s: \"%s\" size (%d) should be %d!\n", + if (field->size != size && field->size != alternate_size) { + pr_debug("%s: \"%s\" size (%d) should be %d", evsel->name, name, field->size, size); + if (alternate_size > 0) + pr_debug(" or %d", alternate_size); + pr_debug("!\n"); ret = -1; } return ret; } +static int evsel__test_field(struct evsel *evsel, const char *name, + int size, bool should_be_signed) +{ + return evsel__test_field_alt(evsel, name, size, -1, should_be_signed); +} + int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtest __maybe_unused) { struct evsel *evsel = evsel__newtp("sched", "sched_switch"); @@ -42,7 +53,8 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes return -1; } - if (evsel__test_field(evsel, "prev_comm", 16, false)) + if (evsel__test_field_alt(evsel, "prev_comm", TASK_COMM_LEN_16, + TASK_COMM_LEN, false)) ret = -1; if (evsel__test_field(evsel, "prev_pid", 4, true)) @@ -54,7 +66,8 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes if (evsel__test_field(evsel, "prev_state", sizeof(long), true)) ret = -1; - if (evsel__test_field(evsel, "next_comm", 16, false)) + if (evsel__test_field_alt(evsel, "next_comm", TASK_COMM_LEN_16, + TASK_COMM_LEN, false)) ret = -1; if (evsel__test_field(evsel, "next_pid", 4, true)) @@ -72,7 +85,8 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes return -1; } - if (evsel__test_field(evsel, "comm", 16, false)) + if (evsel__test_field_alt(evsel, "comm", TASK_COMM_LEN_16, + TASK_COMM_LEN, false)) ret = -1; if (evsel__test_field(evsel, "pid", 4, true)) From patchwork Mon Nov 1 06:04:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595855 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAE69C433EF for ; Mon, 1 Nov 2021 06:04:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 804A160EBC for ; Mon, 1 Nov 2021 06:04:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 804A160EBC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 18B1980017; Mon, 1 Nov 2021 02:04:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13AE580008; Mon, 1 Nov 2021 02:04:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED06480017; Mon, 1 Nov 2021 02:04:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id D9C8F80008 for ; Mon, 1 Nov 2021 02:04:51 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 975AD545CB for ; Mon, 1 Nov 2021 06:04:51 +0000 (UTC) X-FDA: 78759322782.24.69D3F38 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf25.hostedemail.com (Postfix) with ESMTP id 4436AB000184 for ; Mon, 1 Nov 2021 06:04:43 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id 75so16328362pga.3 for ; Sun, 31 Oct 2021 23:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=d7LTw3kPVa/zFmJb8s8WHpppDtuC/dCZbGEz654o0Z0=; b=H/Nt6ip1DACtHq57o9Mdyh3bCgZ2fAcALeHvM0Gv+XQbwcYyRHXWzojtO6xw8zIvFg of7ARcpuxOICZBLLWsgHgEjiLZ0NGPmGsuSOqYNFLvMqSv4w8r/p8nLl5pblmv9MgEXK 21ou7ksmzx/LPZaw79nrvSnwPYYF223o7/HBbYq0pHxF7nGPcAxZCCl6cOjOw/p4oGNc VxIcq8UNpcJv+RFjFLhBnY8fbD5NrNaZXXYN5J97DSOc3G3PRDERiKp/Ha/Guhftz0eU E9yXRyZQp5jPEOXF7gKMmJZHCv2oeodhDAX0AAFrN+gmh4zIDj2PfHr03avz0ORhIkM/ aw+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d7LTw3kPVa/zFmJb8s8WHpppDtuC/dCZbGEz654o0Z0=; b=XyZREb4mWBq8l8nIuoVmQx8YMAtswqKJp++2dApD/h7OH0n9w8fyC+p6F1H7Fr9CwU w5qnTcwr6Wpvb0OTtQ7/mYA1iTXSeEwjQWBwKPhu7bNu+34Pp0/GbuSDhfnqsEyXbtVH xpzogDAsTYy88ZSHN0p9ODr17IDaWdVzgudlUZQwvcsx6l7+QzpAw52JkxceDrbVM+Tz n4OQfzM+O0btPjcA6sta0I+AUo3NyOq47DIMdcKzeQ2hICRWDls05o9pvH2JTBn//H2y JoO8uygQOrQsIdHczu8+c+EsLXjtsg8WC5diHz1bhkIhRf1Z4J8JkAI0X+Cg9YfNQhb3 510Q== X-Gm-Message-State: AOAM5315JmlY42wzxzgEiEM9ic7Yy2vg2smOVcH4oesEBzG/dbn8zLId dnAfRwlkXCm25FMwgGNfIgY= X-Google-Smtp-Source: ABdhPJxHtNbH9HB5n5DPJRDQzLHf3MgJ9R6ynW9CWqOunCISp1/PBfsWZl/KKejsKvsqjLu1N78mrQ== X-Received: by 2002:a63:7e05:: with SMTP id z5mr20295506pgc.354.1635746690496; Sun, 31 Oct 2021 23:04:50 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:49 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v7 09/11] tools/testing/selftests/bpf: make it adopt to task comm size change Date: Mon, 1 Nov 2021 06:04:17 +0000 Message-Id: <20211101060419.4682-10-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4436AB000184 X-Stat-Signature: wj3c1hp7gedypkokmq1ah7mqn7qqjo5z Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="H/Nt6ip1"; spf=pass (imf25.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1635746683-912581 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: The hard-coded 16 is used in various bpf progs. These progs get task comm either via bpf_get_current_comm() or prctl() or bpf_core_read_str(), all of which can work well even if the task comm size is changed. In these BPF programs, one thing to be improved is the sched:sched_switch tracepoint args. As the tracepoint args are derived from the kernel, we'd better make it same with the kernel. So the macro TASK_COMM_LEN is converted to type enum, then all the BPF programs can get it through BTF. The BPF program which wants to use TASK_COMM_LEN should include the header vmlinux.h. Regarding the test_stacktrace_map and test_tracepoint, as the type defined in linux/bpf.h are also defined in vmlinux.h, so we don't need to include linux/bpf.h again. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek Acked-by: Andrii Nakryiko --- include/linux/sched.h | 9 +++++++-- tools/testing/selftests/bpf/progs/test_stacktrace_map.c | 6 +++--- tools/testing/selftests/bpf/progs/test_tracepoint.c | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index b9c85c52fed0..09ac13e54549 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -274,8 +274,13 @@ struct task_group; #define get_current_state() READ_ONCE(current->__state) -/* Task command name length: */ -#define TASK_COMM_LEN 16 +/* + * Define the task command name length as enum, then it can be visible to + * BPF programs. + */ +enum { + TASK_COMM_LEN = 16, +}; extern void scheduler_tick(void); diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c index 00ed48672620..e9b602a6dc1b 100644 --- a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c +++ b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2018 Facebook -#include +#include #include #ifndef PERF_MAX_STACK_DEPTH @@ -41,11 +41,11 @@ struct { /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ struct sched_switch_args { unsigned long long pad; - char prev_comm[16]; + char prev_comm[TASK_COMM_LEN]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN]; int next_pid; int next_prio; }; diff --git a/tools/testing/selftests/bpf/progs/test_tracepoint.c b/tools/testing/selftests/bpf/progs/test_tracepoint.c index 4b825ee122cf..f21982681e28 100644 --- a/tools/testing/selftests/bpf/progs/test_tracepoint.c +++ b/tools/testing/selftests/bpf/progs/test_tracepoint.c @@ -1,17 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2017 Facebook -#include +#include #include /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ struct sched_switch_args { unsigned long long pad; - char prev_comm[16]; + char prev_comm[TASK_COMM_LEN]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN]; int next_pid; int next_prio; }; From patchwork Mon Nov 1 06:04:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595857 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 258A6C4332F for ; Mon, 1 Nov 2021 06:04:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D1BD460EBC for ; Mon, 1 Nov 2021 06:04:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D1BD460EBC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7094780018; Mon, 1 Nov 2021 02:04:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6946B80008; Mon, 1 Nov 2021 02:04:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 470C180018; Mon, 1 Nov 2021 02:04:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id 2A8C080008 for ; Mon, 1 Nov 2021 02:04:54 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DF1CC3A7DE for ; Mon, 1 Nov 2021 06:04:53 +0000 (UTC) X-FDA: 78759322866.09.4B907F3 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf26.hostedemail.com (Postfix) with ESMTP id 5010720019C9 for ; Mon, 1 Nov 2021 06:04:54 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id gb13-20020a17090b060d00b001a674e2c4a8so1909120pjb.4 for ; Sun, 31 Oct 2021 23:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LvSuBTtzWbrXgjb4RLiUJa0DKbJeUJhJDjpVybnmpmo=; b=Mons/lRRxlmoaqOVtmFZnSu86Gkf5r4H5cY0kniY9gdH+szl8upHhpaZR7MR4xQ4tw dE2pI6UqL1jzYM4vvLqKghrUPQDn79hRqU7KxiMF+5YggE6jafzi9LymBwddjrin53xA DS/vBbsVNijV75Vx09TumG5j4U1GZmxVHVKUrh58sYOCTTMBcRzBvqBQmlqQjnp9UiE6 CSWjjS2dsqFC7BDjyMH2pF3tVsU6TtlHkUNzoI8cXteZR0F4qZ685VNLWN0UoeXzxvyY 29Os19nVMJ2skD60ZUbljxErtaiTL7ovw6A0gtYiuQbZsZ494tasBFvKYe9V+eptBdn1 Gtvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LvSuBTtzWbrXgjb4RLiUJa0DKbJeUJhJDjpVybnmpmo=; b=28KALFhrk28EjZiNTyHWnHW+Ie0l2xpfSM8wa36Tz0kNFyOQB/iWKFlkuQ89dahsXv Si7NH0leMpWJ1V+BlhlygVGFNBfsX/wioYziDBH97Uc6XknHmmTMoOhxB2/1jY6dmCyH iSXs7Hyx1VkjXhvtQxSZqHsLbsqxJzIlNjd2ugMoixl7AOAUw6eVyeZMv2xW+iHADliY yYe2euHxj1BqMTImm6bfB5SAxcD1vfsAVQfSiDmHm0RspqbhIp5loGRUp/bHI/Xe40Ml X4f85CqQfU4Duql3kUH0zHB//Jq95jSdcgIiuy/jXu+k6zk2AGULEZqR93y8LBFSzKIc fXcQ== X-Gm-Message-State: AOAM532z7aABnHgS6MTSxHxvqOO8e9CrLqTqsMhCKpitc5OgWAGl5pbV PCZcphLTc5Yo5kDv/OuBRdk= X-Google-Smtp-Source: ABdhPJx4c5pscRjAJUsqapKZZ8TRE5l4wRfA5yn4IJZjx67PGHHeSXi7SUSuCfLV4PBYO3mVczta1w== X-Received: by 2002:a17:90b:3149:: with SMTP id ip9mr33599543pjb.45.1635746692795; Sun, 31 Oct 2021 23:04:52 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:52 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 10/11] sched.h: extend task comm from 16 to 24 Date: Mon, 1 Nov 2021 06:04:18 +0000 Message-Id: <20211101060419.4682-11-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 5010720019C9 X-Stat-Signature: 8n5tqaorerntn1kxutuq85mdj6uauumb Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Mons/lRR"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-HE-Tag: 1635746694-687922 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: When I was implementing a new per-cpu kthread cfs_migration, I found the comm of it "cfs_migration/%u" is truncated due to the limitation of TASK_COMM_LEN. For example, the comm of the percpu thread on CPU10~19 are all with the same name "cfs_migration/1", which will confuse the user. This issue is not critical, because we can get the corresponding CPU from the task's Cpus_allowed. But for kthreads correspoinding to other hardware devices, it is not easy to get the detailed device info from task comm, for example, jbd2/nvme0n1p2- xfs-reclaim/sdf We can also shorten the name to work around this problem, but I find there are so many truncated kthreads: rcu_tasks_kthre rcu_tasks_rude_ rcu_tasks_trace poll_mpt3sas0_s ext4-rsv-conver xfs-reclaim/sd{a, b, c, ...} xfs-blockgc/sd{a, b, c, ...} xfs-inodegc/sd{a, b, c, ...} audit_send_repl ecryptfs-kthrea vfio-irqfd-clea jbd2/nvme0n1p2- ... We should improve this problem fundamentally by extending comm size to 24 bytes. task_struct is growing rather regularly by 8 bytes. After this change, the truncated kthreads listed above will be displayed as: rcu_tasks_kthread rcu_tasks_rude_kthread rcu_tasks_trace_kthread poll_mpt3sas0_statu ext4-rsv-conversion xfs-reclaim/sdf1 xfs-blockgc/sdf1 xfs-inodegc/sdf1 audit_send_reply ecryptfs-kthread vfio-irqfd-cleanup jbd2/nvme0n1p2-8 As we have converted all the unsafe copy of task comm to the safe one, this change won't make any trouble to the kernel or the in-tree tools. The safe one and unsafe one of comm copy as follows, Unsafe Safe strlcpy strscpy_pad strncpy strscpy_pad bpf_probe_read_kernel bpf_probe_read_kernel_str bpf_core_read_str bpf_get_current_comm perf_event__prepare_comm prctl(2) Regarding the possible risk it may take to the out-of-tree user tools, if the user tools get the task comm through kernel API like prctl(2), bpf_get_current_comm() and etc, the tools still work well after this change. While If the user tools get the task comm through direct string copy, it must make sure the copied string should be with a nul terminator. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- include/linux/sched.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 09ac13e54549..a8822e26653e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -276,10 +276,11 @@ struct task_group; /* * Define the task command name length as enum, then it can be visible to - * BPF programs. + * BPF programs. The TASK_COMM_LEN_16 is kept for backward-compitability. */ enum { - TASK_COMM_LEN = 16, + TASK_COMM_LEN_16 = 16, + TASK_COMM_LEN = 24, }; extern void scheduler_tick(void); From patchwork Mon Nov 1 06:04:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595859 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 880FAC433FE for ; Mon, 1 Nov 2021 06:04:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 39FF860EBC for ; Mon, 1 Nov 2021 06:04:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 39FF860EBC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BEB6780019; Mon, 1 Nov 2021 02:04:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B745980008; Mon, 1 Nov 2021 02:04:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9784B80019; Mon, 1 Nov 2021 02:04:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 7A5D080008 for ; Mon, 1 Nov 2021 02:04:56 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3F62618347D9E for ; Mon, 1 Nov 2021 06:04:56 +0000 (UTC) X-FDA: 78759323034.17.6777745 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf15.hostedemail.com (Postfix) with ESMTP id 1061ED00009D for ; Mon, 1 Nov 2021 06:04:46 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id y1so10863729plk.10 for ; Sun, 31 Oct 2021 23:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QKwddORb13OigBCy9mDZcUnsG5h+t9yQLv8LVp5siCU=; b=j5LFKzVUzTdpQtOquEYQiQ93/QxNXDe/080ZPzqen1nnJEcnWv0Arg1m3H5YGUWw8M stUDWkjS1zFBojQqjlqwmgBfiFDvw/FY5w1DdoEUTOEo04//87rHjl76eKfDkRV6JYaD wHniweh+Bt9WBNr9zbaJOafXiibJeSYbktM2cOjCLSm/QMXoinVi4CBxQO0XAGBypciT vft62rQAmLIxRWsns2FxpBvhq592YznXCJfnsuQVHL7l548rjILVi1WcAe1E24RkOJBv 6xba3tgT8iJOTopxgjfSx7YFqWx5gxJbgzz6VMxiVUScwsGxaEWyzxex2OUaialtPu/r 8Emw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QKwddORb13OigBCy9mDZcUnsG5h+t9yQLv8LVp5siCU=; b=m32jYJecOnndjqI7haXaN7GcLfGGQuQJDd4DhbPoXuCoNNnD5qKPyP8riuiCO5GXg8 SSC88T0XBFjyPt6eUrDmJt4MvAmr/6oKx2ulRNVQCk8WOFHBAnJfUpDVZbETrOzROOnh wTOO2ZMH28QkgQbvJz/LcnXaHLh5FUh0hCwGkTaADt3ZrVLGhlmPVJfk7En1tdhx+w8g OG3+0XtqChpjCRM0qRgv/IvpW0iqbp5i4Z3N7f6RyrI6KDYaIAq1mKDxZKSqWS84pbJG 3ZEXZ1B3/E77OoOPgOLknZ4+TTPpbFyNyoieah0wsT48AtEuCW+EQmpa0uKCUjLXf36Q uvYw== X-Gm-Message-State: AOAM533S0EtTq1MSaRpJ0ERXq0Fmv32kDzxkXdYsUYaN7MvC7pAPclBS BscowuRHBCYCp5mGn/j62P4= X-Google-Smtp-Source: ABdhPJyrJq+mOKZ0lf2kZ6Y6bPXWfxcFbUFKsxFZDJ2CDMm20OFCcbYj+83X+q3vioiE0f2mNOqwFQ== X-Received: by 2002:a17:90a:930c:: with SMTP id p12mr36038293pjo.176.1635746695055; Sun, 31 Oct 2021 23:04:55 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:54 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 11/11] kernel/kthread: show a warning if kthread's comm is truncated Date: Mon, 1 Nov 2021 06:04:19 +0000 Message-Id: <20211101060419.4682-12-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=j5LFKzVU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-Stat-Signature: yo87u3ysz5cbnfw6cob38yacb84byf4j X-Rspamd-Queue-Id: 1061ED00009D X-Rspamd-Server: rspam01 X-HE-Tag: 1635746686-373454 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: Show a warning if task comm is truncated. Below is the result of my test case: truncated kthread comm:I-am-a-kthread-with-a-l (pid:178) by 8 characters As we have extended task comm to 24, all the existing in-tree kthreads/workqueues are not truncated anymore. So this warning will only be printed for the newly introduced one if it has a long name. Suggested-by: Petr Mladek Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- kernel/kthread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index 5b37a8567168..63f38d3a4f62 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -399,12 +399,17 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), if (!IS_ERR(task)) { static const struct sched_param param = { .sched_priority = 0 }; char name[TASK_COMM_LEN]; + int len; /* * task is already visible to other tasks, so updating * COMM must be protected. */ - vsnprintf(name, sizeof(name), namefmt, args); + len = vsnprintf(name, sizeof(name), namefmt, args); + if (len >= TASK_COMM_LEN) { + pr_warn("truncated kthread comm:%s (pid:%d) by %d characters\n", + name, task->pid, len - TASK_COMM_LEN + 1); + } set_task_comm(task, name); /* * root may have changed our (kthreadd's) priority or CPU mask.