From patchwork Thu Oct 21 03:45:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12573717 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 A8C95C433FE for ; Thu, 21 Oct 2021 03:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92397610CB for ; Thu, 21 Oct 2021 03:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231349AbhJUDrm (ORCPT ); Wed, 20 Oct 2021 23:47:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbhJUDrk (ORCPT ); Wed, 20 Oct 2021 23:47:40 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0D83C06161C; Wed, 20 Oct 2021 20:45:24 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id n8-20020a17090a2bc800b00196286963b9so2104931pje.3; Wed, 20 Oct 2021 20:45:24 -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=28QPdPbMM0S7NoiSQs1dCJ5bnkQ4h4CQgKgI92E1QJM=; b=qOz60AwTnCiKiUWe4HE41jrZ+BKODIChNBbP9NvsAV5cyHgsYNeZ+IfsChK6Do8ElD aJQEumMUjDSqyb/VMuMPAGxAsDORyieDVTA2f1x4Cpi8yvzQwAceSSXQYGOpV3LZObsk yDVtGeRN/boWfT5viVGTXpHOJo60nDwzDo/qD5timMFe1mm696m+TC2XRzcW3+7aHU4e VGqj+5fl9K8WcRyoL+0IdtJu8U1uKxMUoAwn7rc7k/L4FwB2Lmxb64g51H2Xr2BLMbF0 WHxfe8my6XLrEDSCgP0IMBusVbEY1qR1jOd29A3HgzMtaszsKT1vbLlUd7d6rV+8EK41 lUUA== 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=28QPdPbMM0S7NoiSQs1dCJ5bnkQ4h4CQgKgI92E1QJM=; b=GXCrgBEoLtytDMaew5ipf3pujJOKZ+JvmgJF62t40wMOrKB0mUPYY57h2kXKNvzJM0 k4X/p1ajI85M5OO/jsPt5K6hG5VgwXiF1WYdGugpdwes+Ol3w29iuFWcDVcpJhZcVUXY 6gtuWEXkNiQihzeblGzpuF74TSyLWK5CdcTjXb7zyciK/GAJdQv3cSe8vOM//w4QyUMC tSOiEwKaTQSgW4dYccIyQ4wYnMTycVmlC8+2eGWl1MhiTwxAitslZgCUuICjgxZRRHvc u95zWKazL9aRpNFZO4QSMYxqajMZV22oLu9zoVe+Ko6uUtaT9lMLOpTFYMb/MDd5ZR68 zrQQ== X-Gm-Message-State: AOAM530B/4uq63R9jQTWLWlSr44llvm4TGp6FceS/E2A6Lcr1u41IfM9 ISuBXfGpaBp5mcze6NU7nYA= X-Google-Smtp-Source: ABdhPJwWBsB448ybVlkRj/zgX0cJ3bKycqnAj+2th0i2ArJsDGTY3F0BqghbcV/C/ZJwOtE6AUjtWw== X-Received: by 2002:a17:902:f703:b029:12c:982:c9ae with SMTP id h3-20020a170902f703b029012c0982c9aemr3018202plo.20.1634787924373; Wed, 20 Oct 2021 20:45:24 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:24 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 01/15] fs/exec: make __set_task_comm always set a nul ternimated string Date: Thu, 21 Oct 2021 03:45:08 +0000 Message-Id: <20211021034516.4400-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Make sure the string set to task comm is always nul ternimated. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers 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 Thu Oct 21 03:45: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: 12573715 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 24E7EC43217 for ; Thu, 21 Oct 2021 03:45:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0030060ED3 for ; Thu, 21 Oct 2021 03:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231408AbhJUDro (ORCPT ); Wed, 20 Oct 2021 23:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230434AbhJUDrl (ORCPT ); Wed, 20 Oct 2021 23:47:41 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 537E6C061749; Wed, 20 Oct 2021 20:45:26 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id e65so21954956pgc.5; Wed, 20 Oct 2021 20:45:26 -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=mDqWI6DfAAoDrLo3HMtLvXltC73eryXlWAxq3memVRQ=; b=oQDNAwXWou41LOl80lo8mym0MDCLiuHjXO7v9kWV3cgDj69RcxN4Fqi/YudxpJ4JvP 4pLuXYNMaqjt43GVYo3zEp/KhSW3inmk6rKcfH6RjMgIiAiCV4ACc88Zm7UKGy19fXKr oEJtYq3eUQ4TSR0lEQ96UVlsitDmgApqgujoQi57xKjYI3qEjXO1AOVhhMGgYBvQPyA2 H9Rz/OJ4XIOxXrsUUqKtijGWQRZYt7eBPr04TKafbfBYE/mYK4+9io4dd/tVMwcCMA1t pJlJfvxQEhus0IFpNSu/p3E42PGM+pbOokwU4nf/D8lMJ4mUXlQtMVGzQhDJeTA7H/gV HGFw== 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=mDqWI6DfAAoDrLo3HMtLvXltC73eryXlWAxq3memVRQ=; b=ZOMoDemTgGoJJlNpH9HphLa3DOeHkkmglTOo3QU28JRZXVb4KFLC8VRJxUGRrdEnrL EQrb3FGQyzMb+2F7Q9NewkWRVMcWG5BN8jeOKDYhqu+XwugEZqsbW9IEH0XvUbAHcKUi mxZL/y9U7V8mIaEmm0JgY0wXlxGQ4cfdfV3R5drqIcYOhzQ+Xf6nlh1O0YWrxDVnzA8R dxKeoT0yJ1TAa5o6vyHqa4k6GMnN31D2877YfwYBum2i1RSsQfWXsACa1vtWF0YbdeZK h+d/UPEqje6bDGfTf6iHRi1MU921MwtJclSqNNJ7gyJAWACV8JhMIZMA2iyl5RPF2kZI kRuw== X-Gm-Message-State: AOAM531cfImUqcWBQmN2ziiIyXthn0VDpj8Fq9/G9xX8lWA7UsfvP8/X cB0lGEVsmMfKwe53xbA7LWo= X-Google-Smtp-Source: ABdhPJzt12FbvYv0cicHz5ns1lHPJX4II4BhTrW6My4SGjQ6OedpZBZQ+woR9E5vRQ1Xp8+0MpZ2Sg== X-Received: by 2002:a05:6a00:1686:b0:44d:50e:de9e with SMTP id k6-20020a056a00168600b0044d050ede9emr3012092pfc.4.1634787925875; Wed, 20 Oct 2021 20:45:25 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:25 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 02/15] fs/exec: make __get_task_comm always get a nul terminated string Date: Thu, 21 Oct 2021 03:45:09 +0000 Message-Id: <20211021034516.4400-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Cc: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro 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..bf2a7a91eeea 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); + /* The copied value is always null terminated */ + strscpy_pad(buf, tsk->comm, buf_size); task_unlock(tsk); return buf; } From patchwork Thu Oct 21 03:45: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: 12573719 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 CA71DC43217 for ; Thu, 21 Oct 2021 03:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0367610CB for ; Thu, 21 Oct 2021 03:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231463AbhJUDrs (ORCPT ); Wed, 20 Oct 2021 23:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231387AbhJUDrn (ORCPT ); Wed, 20 Oct 2021 23:47:43 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF5C9C06161C; Wed, 20 Oct 2021 20:45:27 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id a15-20020a17090a688f00b001a132a1679bso2130747pjd.0; Wed, 20 Oct 2021 20:45:27 -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=Yf2NA38E7HKQh3ZYZFbNhGoKPtNwpPAehy4wTF5rYbw=; b=WVDgEDcA6KG/3I8xJsCT5rM/9VEakGIavjAQJNDeLjTLTQSb+a+nrxflwc7YKGtx8y xyD8IFwuTFIMqw4o0L6Q1yGVc1WdMnR4+MJlTUaoGw8IRB+smDqlCnlvjiPB5Bfv6IbG arMXnuqzbvvD0+/NYHfkYUbURjxE8zVyqXMixtuBangeQgXt4DsHAnmIfSoxlUGst2w2 yQuOEJmpvKcdCHRxb2QEiYAhZf3rgRnY0PUtRJ9P4Y6bEWpvEV7EBQi745at1CSic/C2 t6FkL3l+AH9p459kgn0orPiPFoILcANQm9P9vFkKlDff7hTs1OatRa1pjJjSnLgUteHR giZA== 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=Yf2NA38E7HKQh3ZYZFbNhGoKPtNwpPAehy4wTF5rYbw=; b=PTonhinuaJRQgwvomji+L/2+/IflpsIRr/XioZFoRi99N6lT0PzD48E7hfNQyG3Wq0 8Co3Qrr7fwAyQCTnVzkKn7FYai7dLCmIsK6oAI+F3vXFlLhEQ06cIeogxGH+eIf6FkBy Rz+j4bs7EG3alUzRED8z3+/gWj1emnyTERvA0cIldQpaHlzwNfpJwyUsf8IpCEgQ6n9W aj/tFO/+RrjjGJrUK69jsywgRKB5E10jHYht7q8z4h0grRf6k/zqMhFZWRexLCDC+SOt XNzrZIQtYRW9pYofFYwpuKG3AC9mpvxlr2N0LO3TQMAU+1ZICMkDfDwX+H4FaTmFFcwK uCgA== X-Gm-Message-State: AOAM530kr9IRQ+skDENR7PYERC3pBM2Xpkdooe2+D2mWhAQ2Bh9VwT9P YZY0jMo3nPn1oH+Ce2uMjws= X-Google-Smtp-Source: ABdhPJxz3hWBQRlpWrPqkNFFP9tU24MK5z/srBRYoQg7h3+iIRdWFNb4CHP8AYDtAUhSGM0Ey9N4YA== X-Received: by 2002:a17:90b:4a4d:: with SMTP id lb13mr2877701pjb.122.1634787927391; Wed, 20 Oct 2021 20:45:27 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:27 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 03/15] sched.h: introduce TASK_COMM_LEN_16 Date: Thu, 21 Oct 2021 03:45:10 +0000 Message-Id: <20211021034516.4400-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There're many hard-coded 16 used to store task comm in the kernel, that makes it error prone if we want to change the value of TASK_COMM_LEN. A new marco TASK_COMM_LEN_16 is introduced to replace these old ones, then we can easily grep them. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- include/linux/sched.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index c1a927ddec64..62d5b30d310c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -274,6 +274,8 @@ struct task_group; #define get_current_state() READ_ONCE(current->__state) +/* To replace the old hard-coded 16 */ +#define TASK_COMM_LEN_16 16 /* Task command name length: */ #define TASK_COMM_LEN 16 From patchwork Thu Oct 21 03:45:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12573721 X-Patchwork-Delegate: kuba@kernel.org 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 D0440C433F5 for ; Thu, 21 Oct 2021 03:45:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA4A860ED3 for ; Thu, 21 Oct 2021 03:45:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231605AbhJUDsA (ORCPT ); Wed, 20 Oct 2021 23:48:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231419AbhJUDro (ORCPT ); Wed, 20 Oct 2021 23:47:44 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 889A8C06161C; Wed, 20 Oct 2021 20:45:29 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id e5-20020a17090a804500b001a116ad95caso3936884pjw.2; Wed, 20 Oct 2021 20:45:29 -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=pevXqfzk0a9mco3A0IBMgl8TtIgUhm0DLJ2rQWdresY=; b=IVwXWPNp0IB5AtbRdxHUftVBA0ZHtHlUfYqroePI4Bxa5n4Ma6otf2aJulMSuhuuKb K8CZmXaK9cs+CruHG4RH2qzM1AI1JA7J3iE41C8D4uTvGuWuhzLdhHUJHInTFpK43vKP 4HtzYVm/t41Lswbr0WKIpitoFeFuNg+ZT8hWSHi9RlVeEfTPxG4kwGtLRTgOzRxJdoUW TbA8cDOX3VNZ3RK4zzU/kVAE7BdFLcrYEoFZgBbP6F0bWBvYQ/v0WERZOB7b9vRrcNSM GpuyMj2lxGjmoYaFk8k5By37qtykRrLVhcNRViPcofYw1EcA0FQiFE0IwTMvXfX+5e6N SzYw== 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=pevXqfzk0a9mco3A0IBMgl8TtIgUhm0DLJ2rQWdresY=; b=YgHQNYIt8nKRln6sxNqEQuJsGtRhltipSkWbUwGytK95ONbyAGiUD8/77tBEt65wbN wX2VBDWm8woFIzP2T5xJVa93rWM98uRBc8LlJKqwr3ncJKWkOaMl0Vz4Y+RI59Qb5MzN Lvuc95/P3HnzpJoQgr5PM/k/Sm4Vo4z1sSqYt9/QMPDGVADGVCDZ6zl27PZgEH643Ath /BgPk3anv8xg/V94g/j8KwHUy820TuK63iTZw22bATwB0SwwvONhFyf5245qIc1RZGw9 RRpif33ANCHeg4yahtKgNOLgCmsB4kY6sXkUDeYp2axwSp4jaJAcYGceCpRoUuxaB918 c2rg== X-Gm-Message-State: AOAM533hmEY7n6F+xQAaFKKZHtV13Uuk7UwPYVibJjOvu/JrhxSdYAN5 lw8XmjHJ+Q7CmDcnM3+SfwM= X-Google-Smtp-Source: ABdhPJzp/IAql6drxO3acK8js1zsIW44wduMnkGkdnmstbT+jEsLlxRzHZdGqHVLATuxVGcoPrc6Pg== X-Received: by 2002:a17:90b:2494:: with SMTP id nt20mr2200494pjb.19.1634787929138; Wed, 20 Oct 2021 20:45:29 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:28 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Vladimir Zapolskiy , David Howells Subject: [PATCH v5 04/15] cn_proc: make connector comm always nul ternimated Date: Thu, 21 Oct 2021 03:45:11 +0000 Message-Id: <20211021034516.4400-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org connector comm was introduced in commit f786ecba4158 ("connector: add comm change event report to proc connector"). struct comm_proc_event was defined in include/linux/cn_proc.h first and then been moved into file include/uapi/linux/cn_proc.h in commit 607ca46e97a1 ("UAPI: (Scripted) Disintegrate include/linux"). As this is the UAPI code, we can't change it without potentially breaking things (i.e. userspace binaries have this size built in, so we can't just change the size). To prepare for the followup change - extending task comm, we have to use __get_task_comm() to avoid the BUILD_BUG_ON() in proc_comm_connector(). __get_task_comm() always get a nul terminated string, so we don't worry about whether it is truncated or not. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Vladimir Zapolskiy Cc: Peter Zijlstra Cc: Steven Rostedt Cc: David Howells Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- drivers/connector/cn_proc.c | 5 ++++- include/uapi/linux/cn_proc.h | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c index 646ad385e490..c88ba2dc1eae 100644 --- a/drivers/connector/cn_proc.c +++ b/drivers/connector/cn_proc.c @@ -230,7 +230,10 @@ void proc_comm_connector(struct task_struct *task) ev->what = PROC_EVENT_COMM; ev->event_data.comm.process_pid = task->pid; ev->event_data.comm.process_tgid = task->tgid; - get_task_comm(ev->event_data.comm.comm, task); + + /* This may get truncated. */ + __get_task_comm(ev->event_data.comm.comm, + sizeof(ev->event_data.comm.comm), task); memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ diff --git a/include/uapi/linux/cn_proc.h b/include/uapi/linux/cn_proc.h index db210625cee8..4bb7f658fcc0 100644 --- a/include/uapi/linux/cn_proc.h +++ b/include/uapi/linux/cn_proc.h @@ -21,6 +21,11 @@ #include +/* We can't include directly in this UAPI header. */ +#ifndef TASK_COMM_LEN_16 +#define TASK_COMM_LEN_16 16 +#endif + /* * Userspace sends this enum to register with the kernel that it is listening * for events on the connector. @@ -110,7 +115,7 @@ struct proc_event { struct comm_proc_event { __kernel_pid_t process_pid; __kernel_pid_t process_tgid; - char comm[16]; + char comm[TASK_COMM_LEN_16]; } comm; struct coredump_proc_event { From patchwork Thu Oct 21 03:45: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: 12573723 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 4F350C4332F for ; Thu, 21 Oct 2021 03:45:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D2AC60ED3 for ; Thu, 21 Oct 2021 03:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231450AbhJUDsE (ORCPT ); Wed, 20 Oct 2021 23:48:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbhJUDrq (ORCPT ); Wed, 20 Oct 2021 23:47:46 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A198C061749; Wed, 20 Oct 2021 20:45:31 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id f11so4678978pfc.12; Wed, 20 Oct 2021 20:45:31 -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=oLYk/nD4kzrtWbwdTYVlHSm8i/eV6joSd3D35BwjCQk=; b=aaiMYPCQn+0hi5MXqNtDnJEfzrMZUorhEEnTJ6rfRf0JnQGB8IoIWJEx7LdOiZ8uqY 8NRxGR0aYJ8ix53+oUUnf2qcs3hWmqA+gt/VWU/a6/1Q9qyGgc9viYz4LFiApzUOmEGA MCtOLZC4wEHSiZ2EviisDOKWo8gzv52k2udp1tRaG2lW6mZX/QTQ0h0Bj1hq7tVqRJ62 d45Mwwlb5p2uEutRRn0PhUogqhXSqODxf04xpfrJQE9oqEclaT2TnMB52ev3OdnjQGLm WJuPBvOsCnhIYqFG03W5rHa2+I8/abTa1nFZfDIlyB+u3HVkAemuBA8CzOOJV/F/KwQh hrzA== 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=oLYk/nD4kzrtWbwdTYVlHSm8i/eV6joSd3D35BwjCQk=; b=ou2+g7UfOy/b2jOeGWvQ/OK3gemMhiBAJ4D8kcXcnTrWeQxFIlqRd9lIr6xE6mGL9T geLfH9GlRfewgMo5biSUTsoN/E6PRZMf4XGA+og+nbXNa/S2wfWucA/Fw7S27mNMD7TW dp+hNBtiGcut+wLJ9f2F9Cw2Xka4flTGqQ5LHpWEQ0UtDF/+dypagix+j/HNldcnzhWl O5km1OfEwhK5F4OPzjq8QgOo+GHKp9Gu10Ge8FBfpwFxzKN4qdaqSJi5BWd9Bn7v3olS rOBHxf/7fxB21gt0PRr5QKkXDqRfHezv5kwhebC/ww9VkiWD/CYaM6ym5xxAU2+rjSax 0StA== X-Gm-Message-State: AOAM533UlWoTbFrMgwcv/4Uwb+0gN3sHRnXmHM7VEhWFEt3yNDYDFKfE rHcDPRBWv8JE6/ALMqM99m4= X-Google-Smtp-Source: ABdhPJwjAK6tR17GoaDLDsq/wwuZQycmJQypGuO/d9ZCYYtL/8SMkeO0WSuTCg3UZQT6eNsXzVijxw== X-Received: by 2002:a63:920b:: with SMTP id o11mr2481210pgd.314.1634787930634; Wed, 20 Oct 2021 20:45:30 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:30 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 05/15] drivers/infiniband: make setup_ctxt always get a nul terminated task comm Date: Thu, 21 Oct 2021 03:45:12 +0000 Message-Id: <20211021034516.4400-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use TASK_COMM_LEN_16 instead of hard-coded 16 to make it more grepable, and use strscpy_pad() instead of strlcpy() to make the comm always nul terminated. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- drivers/infiniband/hw/qib/qib.h | 4 ++-- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h index 9363bccfc6e7..8e59f9cbabc8 100644 --- a/drivers/infiniband/hw/qib/qib.h +++ b/drivers/infiniband/hw/qib/qib.h @@ -195,8 +195,8 @@ struct qib_ctxtdata { /* pid of process using this ctxt */ pid_t pid; pid_t subpid[QLOGIC_IB_MAX_SUBCTXT]; - /* same size as task_struct .comm[], command that opened context */ - char comm[16]; + /* task_struct .comm[], command that opened context */ + char comm[TASK_COMM_LEN_16]; /* 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..7ab2b448c183 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)); + strscpy_pad(rcd->comm, current->comm, sizeof(rcd->comm)); ctxt_fp(fp) = rcd; qib_stats.sps_ctxts++; dd->freectxts--; From patchwork Thu Oct 21 03:45: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: 12573725 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 E08F6C4332F for ; Thu, 21 Oct 2021 03:45:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAD6960ED3 for ; Thu, 21 Oct 2021 03:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbhJUDsG (ORCPT ); Wed, 20 Oct 2021 23:48:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbhJUDrv (ORCPT ); Wed, 20 Oct 2021 23:47:51 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8922BC061755; Wed, 20 Oct 2021 20:45:32 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id s136so21131316pgs.4; Wed, 20 Oct 2021 20:45: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=IFlJQvgcVFayHxxxZOKIVduulLCEIS8IL4o5ynS1C+Y=; b=UV8lW+/u1hTpRZJeCHc5TAt9vjBVIKt3Djp229X12qYrvSLGxWW1bKeiw+35AbdgHZ WTHz3f4L3AEy4IcO4pxMCxOofNj3ssteEGzxBpB+qYEtsB6hOybtEFf3eU573jsSgpUE Nwjn4G9sdOwsZs39sVNKcDy01eHIktFDOO2ioKO9LlyLYiqocG7RJgjuC/LM5CjJE42j ySBHVs2Rqa6BOsWToOPQoyUJ3vEmMgzACPy6muR0ZkQcLZDG2ThP3p2GVvto9g+wsEWM g0Jiw1B4Ew61OZS3bljvYjzsQ9AL94rVWrEN6LADvLRsKcdK8mu4n5ijbRADRGbgAiVE b4Sw== 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=IFlJQvgcVFayHxxxZOKIVduulLCEIS8IL4o5ynS1C+Y=; b=uTA8Q/0hWLp40hntGN7fIhWK/m/3q739EKf4os7NSUxUR7myuPPbwXVpReVtnUKB3i 1ROLVgMYMgjaMloLqGHKFwc7lL9DPd6kpjn2cqcCge7Ll0ZoUzD9We77VqW33cTmfeAt Pl6c3vcfVOEgtPq/wL279RNAA4OZh1yb2294ACWCs9mgklICLbdmLvdKtEBE9+SKsP5+ 4lVWXUVcl/cjMFG2+N/jPUSXeWVkrFbDkeznXq4Q1v1B0TVnptY33dwZNeDY+PIQvBB1 XkKEjFUIaoLZpnz3zDFEprt2pv2tFbKMyDEoNoYb3w2JyKxm3w+meOy8GnlYz5e87LfR j95w== X-Gm-Message-State: AOAM533B9KBctyylL9ei5cJuYTz6ncheGbkqmdaqnY+H638t9vreSsWj nkd1EotKCwCUr70/TfpdWQE= X-Google-Smtp-Source: ABdhPJw3tJ4+yRDaDe8c44srjX2Pyw7/4ELqqc0tR6rMgxRse+mdX70FULOBuOH5G3XvimxzcYd6cw== X-Received: by 2002:a63:d80c:: with SMTP id b12mr2541097pgh.331.1634787932148; Wed, 20 Oct 2021 20:45:32 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:31 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 06/15] elfcore: make prpsinfo always get a nul terminated task comm Date: Thu, 21 Oct 2021 03:45:13 +0000 Message-Id: <20211021034516.4400-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This patch can fix this warning. struct elf_prpsinfo is used to dump the task information in userspace coredump or kernel vmcore. Use TASK_COMM_LEN_16 instead of hard-coded 16 to make it more grepable, and use strscpy_pad() instead of strncpy() to make it always get a nul terminated task comm. Reported-by: kernel test robot Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- fs/binfmt_elf.c | 2 +- include/linux/elfcore-compat.h | 3 ++- include/linux/elfcore.h | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index a813b70f594e..a4ba79fce2a9 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)); + strscpy_pad(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname)); return 0; } diff --git a/include/linux/elfcore-compat.h b/include/linux/elfcore-compat.h index e272c3d452ce..69fa1a728964 100644 --- a/include/linux/elfcore-compat.h +++ b/include/linux/elfcore-compat.h @@ -5,6 +5,7 @@ #include #include #include +#include /* * Make sure these layouts match the linux/elfcore.h native definitions. @@ -43,7 +44,7 @@ struct compat_elf_prpsinfo __compat_uid_t pr_uid; __compat_gid_t pr_gid; compat_pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid; - char pr_fname[16]; + char pr_fname[TASK_COMM_LEN_16]; char pr_psargs[ELF_PRARGSZ]; }; diff --git a/include/linux/elfcore.h b/include/linux/elfcore.h index 2aaa15779d50..ee7ac09734ba 100644 --- a/include/linux/elfcore.h +++ b/include/linux/elfcore.h @@ -65,8 +65,8 @@ struct elf_prpsinfo __kernel_gid_t pr_gid; pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid; /* Lots missing */ - char pr_fname[16]; /* filename of executable */ - char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */ + char pr_fname[TASK_COMM_LEN_16]; /* filename of executable */ + char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */ }; static inline void elf_core_copy_regs(elf_gregset_t *elfregs, struct pt_regs *regs) From patchwork Thu Oct 21 03:45: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: 12573727 X-Patchwork-Delegate: bpf@iogearbox.net 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 F1688C433EF for ; Thu, 21 Oct 2021 03:45:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF83260FED for ; Thu, 21 Oct 2021 03:45:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231679AbhJUDsI (ORCPT ); Wed, 20 Oct 2021 23:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbhJUDrv (ORCPT ); Wed, 20 Oct 2021 23:47:51 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15838C061768; Wed, 20 Oct 2021 20:45:34 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id h193so8968890pgc.1; Wed, 20 Oct 2021 20:45: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=0QORRqOHwrTwPIk1mXEbyzyPg28H9YEY40+Pmmc8asE=; b=V1HK9LH74t5jFt8aC0mQynUQ0OO5jCHgGHTNpaWFQ7MvGI6et/N8hKxn+fo0ROPbxI X24+vc6jVTq7SBPM7lpRMdzSkXXDvUvwkAEB9Ca288nYX+jdpV20GIBDRvxFJ3OadNKf cc0c+VBrnYfcHYSUxdpLpvNMRLxVlNewekDxhtpJtvYrKLskikR5v+I2CueBT4+hDeKV nLLDLVzSqdX+/mObPaUOvHrS2E481ot8B5QnnlaEgy7kf0DQZKK3cCnoQsfJgpfCzzSw HXQBpcQxdRBDH5PVrxFQ2PMsS2qk34pUvloDV4jFrL4TDJUkfWEytihrp1r8NFYlEww6 SUog== 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=0QORRqOHwrTwPIk1mXEbyzyPg28H9YEY40+Pmmc8asE=; b=3Uvqyb/GyCAbzq8aRqwoDIMCK8K/9qK1LrRzECf5TniaN5UMVxBVK5LW4N4QpP6DW1 WPSIJ5AzjiRZbCyuBgGbapgUvlVNt5u4MfD4eW7R0ZqJRXnEYiErT8/MsogUBMbxpG6K WWEEOW1rouxwEKrhgasnDrEISYyM1bf4O9yauk7X47f7hVBYuhMO+dWeMOoZcBXE9aiY DYPWr2P3XQfEuovYr64HkWnkP37+vWo2eaAmx+esSD01pR4hOKjlBzOwoBEa5CnMLArK OiFrLWFdshDTpbQCwzmLm/UoPHLU7Eneqt4QDTrGNdXjFDNladSeRgj1i8Fc0BC/DIgG dE+A== X-Gm-Message-State: AOAM530UquiW7qy6BhqIbeV/aLrGhZDJEAKycdcIIZArMPDLx5+uUyU2 rVQKTjSgn4pSwwkKvrblUtQ= X-Google-Smtp-Source: ABdhPJxgXH9/K7GGbnXQUIV8CFm64OPrsn3DTVS6Gg2yOvNluWfyUyQctqdOIdAI0ETLuFsED+j9yw== X-Received: by 2002:a63:7d55:: with SMTP id m21mr2488194pgn.436.1634787933676; Wed, 20 Oct 2021 20:45:33 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:33 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 07/15] samples/bpf/kern: use TASK_COMM_LEN instead of hard-coded 16 Date: Thu, 21 Oct 2021 03:45:14 +0000 Message-Id: <20211021034516.4400-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The linux/sched.h is visible to the bpf kernel modules, so we can use TASK_COMM_LEN_16 to replace the hard-coded 16 in these bpf kernel modules to make it more grepable. In these bpf modules, someone gets task comm via bpf_get_current_comm(), which always get a nul terminated string. While someone gets task comm via bpf_probe_read_kernel(), which is unsafe, we should use bpf_probe_read_kernel_str() instead. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- samples/bpf/offwaketime_kern.c | 10 +++++----- samples/bpf/test_overhead_kprobe_kern.c | 11 ++++++----- samples/bpf/test_overhead_tp_kern.c | 5 +++-- samples/bpf/tracex2_kern.c | 3 ++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime_kern.c index 4866afd054da..c0fd04497eea 100644 --- a/samples/bpf/offwaketime_kern.c +++ b/samples/bpf/offwaketime_kern.c @@ -23,8 +23,8 @@ #define MAX_ENTRIES 10000 struct key_t { - char waker[TASK_COMM_LEN]; - char target[TASK_COMM_LEN]; + char waker[TASK_COMM_LEN_16]; + char target[TASK_COMM_LEN_16]; u32 wret; u32 tret; }; @@ -44,7 +44,7 @@ struct { } start SEC(".maps"); struct wokeby_t { - char name[TASK_COMM_LEN]; + char name[TASK_COMM_LEN_16]; u32 ret; }; @@ -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_16]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN_16]; 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..31e8c5ee0cdc 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_16] = {}; + char newcomm[TASK_COMM_LEN_16] = {}; 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..a6d5b3301af2 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_16]; + char newcomm[TASK_COMM_LEN_16]; __u16 oom_score_adj; }; SEC("tracepoint/task/task_rename") diff --git a/samples/bpf/tracex2_kern.c b/samples/bpf/tracex2_kern.c index 5bc696bac27d..d70ce59055cb 100644 --- a/samples/bpf/tracex2_kern.c +++ b/samples/bpf/tracex2_kern.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ static unsigned int log2l(unsigned long v) } struct hist_key { - char comm[16]; + char comm[TASK_COMM_LEN_16]; u64 pid_tgid; u64 uid_gid; u64 index; From patchwork Thu Oct 21 03:45: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: 12573731 X-Patchwork-Delegate: bpf@iogearbox.net 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 01EB2C433F5 for ; Thu, 21 Oct 2021 03:45:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E03E961215 for ; Thu, 21 Oct 2021 03:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231738AbhJUDsM (ORCPT ); Wed, 20 Oct 2021 23:48:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231524AbhJUDrw (ORCPT ); Wed, 20 Oct 2021 23:47:52 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9B06C06176C; Wed, 20 Oct 2021 20:45:35 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id y1so17550205plk.10; Wed, 20 Oct 2021 20:45:35 -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=Uy3o0eBsmouk5ahMP3KJoDGcOIHNVLUaAaLBsszL4+Y=; b=R3/ueHF0dUBx+ft7vo2bPSGoyUu3C6CI1aqEBP6m5imsX+fM2mQ4Ot3GxvdM3LHNzd XWMoQa3fuF1UxkaW38MUMsWv+ujSWksCoV1pYsFbf0ZSWt2FMPcWGHuqlYhQnvZw5tOT X7ExQfMgPbEeqZS2wRiHxl8/QbC/bn2gtZ0lcyx/VCLG73WUJOYnD9s9HxIuKZOdE+1Z GmuNAEIFke4joS9L9jy83Bh3U0azss/r0JvKdy24eMCM7HWxNMHy4HPBgdrKgHKqJKjM Iw9FeNeGB94rbbV72hTF8sHztNkVn8gR6B4MLetGSRSLnyvwLncCAM15Dx00nm+kYeqm S9gg== 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=Uy3o0eBsmouk5ahMP3KJoDGcOIHNVLUaAaLBsszL4+Y=; b=q1PsWzYXTz3A2ia8geZJCdnId/c2JK4Wwfyx0FzmxreeY5p/7bKsVt7Tr0FrciZEP4 U4azgMjLNU1wLyma34uyVnokEcEnfXDLPXqRy0ghQCJGZweUM2xYNbcPifpq/04+fuwF kuzJFuGY+PEIJg26oGiyFyC9DTNFWZj+c0xNp7PqBeZTQxvoK0FDHcYoJXcFNH9V/T3Q fr773DsGIqCQhBfVLi5WPXk4lFRq/cbXbVv+Ci13eFGq4ujxwqYo9RfYd11OLxmJ43RJ jS+xOjGXZv4kHC+x22RAqWZ81/s/32/0OzJAsP6CwjP69ccS+neQ6KCKwBYO66B/IlRU oRGg== X-Gm-Message-State: AOAM532e5CSC4K9Pd4fTlPO0rikFuTxl1EYQfqm1MBztVndhJZNpu9Vc mI/NdpIYnxJPCLl0J9SUYqY= X-Google-Smtp-Source: ABdhPJyW7Ikui+cme9Xhlpd/hF/RWFbJExS2TdOG3kb9pPK5BVi/Aohiu5p1m6CVCaudl1kJ/LW11Q== X-Received: by 2002:a17:90a:de8f:: with SMTP id n15mr3615780pjv.155.1634787935181; Wed, 20 Oct 2021 20:45:35 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:34 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 08/15] samples/bpf/user: use TASK_COMM_LEN_16 instead of hard-coded 16 Date: Thu, 21 Oct 2021 03:45:15 +0000 Message-Id: <20211021034516.4400-9-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The task comm size is invisible to the bpf userspace, we have to define a new TASK_COMM_LEN_16 in the userspace. Use this macro instead of the hard-coded 16 can make it more grepable. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- samples/bpf/offwaketime_user.c | 6 +++--- samples/bpf/tracex2_user.c | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c index 73a986876c1a..ca918ac93ee7 100644 --- a/samples/bpf/offwaketime_user.c +++ b/samples/bpf/offwaketime_user.c @@ -36,11 +36,11 @@ static void print_ksym(__u64 addr) printf("%s;", sym->name); } -#define TASK_COMM_LEN 16 +#define TASK_COMM_LEN_16 16 struct key_t { - char waker[TASK_COMM_LEN]; - char target[TASK_COMM_LEN]; + char waker[TASK_COMM_LEN_16]; + char target[TASK_COMM_LEN_16]; __u32 wret; __u32 tret; }; diff --git a/samples/bpf/tracex2_user.c b/samples/bpf/tracex2_user.c index 1626d51dfffd..70081d917c6d 100644 --- a/samples/bpf/tracex2_user.c +++ b/samples/bpf/tracex2_user.c @@ -10,8 +10,9 @@ #include #include "bpf_util.h" -#define MAX_INDEX 64 -#define MAX_STARS 38 +#define MAX_INDEX 64 +#define MAX_STARS 38 +#define TASK_COMM_LEN_16 16 /* my_map, my_hist_map */ static int map_fd[2]; @@ -28,7 +29,7 @@ static void stars(char *str, long val, long max, int width) } struct task { - char comm[16]; + char comm[TASK_COMM_LEN_16]; __u64 pid_tgid; __u64 uid_gid; }; From patchwork Thu Oct 21 03:45: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: 12573729 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 0D921C433EF for ; Thu, 21 Oct 2021 03:45:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFFCF611C7 for ; Thu, 21 Oct 2021 03:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231703AbhJUDsK (ORCPT ); Wed, 20 Oct 2021 23:48:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231380AbhJUDrw (ORCPT ); Wed, 20 Oct 2021 23:47:52 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 625CEC061749; Wed, 20 Oct 2021 20:45:37 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id b14so7771232plg.2; Wed, 20 Oct 2021 20:45: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=FO6px52zOvL06YEAEvGgHt7D/uuPPxpA7vLGdvmdYfM=; b=WNmzmbXrhFH2nno5IvKecSwjtBp9Sq1uuau/dT4MJbXtKGLvAztn1BspiqME7ie9jT ElhAup4UIC5cL6+b1eX/i/G0lqnjyW2GJyKBbXutPomMQgnucVAuegoq+aer3e0kmeIK G+IYbOusYEVuk9y4PutAERzxqKLouzRE0BDA3FPNkhdC1Q3PcxupW92oFnz1dWdOnlIS 4Tcz8zW4c+HN+W9ZApz2p6CICrqQQ3HZ+HBtQP7s4MIytQ3quGSqGkIQGRYgU0LYV3oH gCDGkw+O3TQMThouBhgLOFPqjoPP1OYoKuTmp9qCInxJi5/wsDyISnA/gqXY0tP5wtLV t76g== 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=FO6px52zOvL06YEAEvGgHt7D/uuPPxpA7vLGdvmdYfM=; b=b+soD0oR6OHqrpohBeSpRTIqBD82r9nwxQP+Cp2Jkdp2nQlmvAS26nBv+m1DbD+8g6 0Z0I7RHIsnr4n44A6sx60ODbbMg/i3UtLu7W8NMVlluVCsTq6QDHiJULJSOz1QbHGUo4 Q7cbU1iDhGKg0gK9umEuBweL9nJAahQ0Z7hJ1bvCHg1oXQVl2T2UQnUH32hSDIE95DmV 6Oi9v3eZmv+rG/SeAs520GWVSkaMSl/2QxzSC5q7CWZH+1OtrW1+AxAPWPY75vBbBdmH ngUm8fdKbkSABSFurh2ZpCey+nzRcbN+BCDYXIySnqzLdcOpGdq71DuLFHZHtPfEIIRq zqMw== X-Gm-Message-State: AOAM53274LGYIjqXJgszPWLfM+KCANXcIH6BwH0u1+7fNJzgxn56wJlL YI5z/ikhtzbfjFOGIn19Zik= X-Google-Smtp-Source: ABdhPJxnEADlrfLm34Bwr231gBIB5s+zQ3Wui9SZ/ZXUE7pRuaq7y0gkzhhBLrZJrNoDqeWyO/tWqA== X-Received: by 2002:a17:90b:3a81:: with SMTP id om1mr3695306pjb.184.1634787936822; Wed, 20 Oct 2021 20:45:36 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id bp19sm3651077pjb.46.2021.10.20.20.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:45:36 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 09/15] tools/include: introduce TASK_COMM_LEN_16 Date: Thu, 21 Oct 2021 03:45:16 +0000 Message-Id: <20211021034516.4400-10-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034516.4400-1-laoar.shao@gmail.com> References: <20211021034516.4400-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org TASK_COMM_LEN_16 is introduced to replace all the hard-coded 16 used in the files under tools/ directory. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- tools/include/linux/sched/task.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/include/linux/sched/task.h b/tools/include/linux/sched/task.h index a97890eca110..7657dd3e0e02 100644 --- a/tools/include/linux/sched/task.h +++ b/tools/include/linux/sched/task.h @@ -1,4 +1,6 @@ #ifndef _TOOLS_PERF_LINUX_SCHED_TASK_H #define _TOOLS_PERF_LINUX_SCHED_TASK_H +#define TASK_COMM_LEN_16 16 + #endif /* _TOOLS_PERF_LINUX_SCHED_TASK_H */ From patchwork Thu Oct 21 03:45:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12573733 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 170A2C4332F for ; Thu, 21 Oct 2021 03:47:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F172961260 for ; Thu, 21 Oct 2021 03:47:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231592AbhJUDt3 (ORCPT ); Wed, 20 Oct 2021 23:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbhJUDtR (ORCPT ); Wed, 20 Oct 2021 23:49:17 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02CBCC06177B; Wed, 20 Oct 2021 20:46:11 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id om14so3914384pjb.5; Wed, 20 Oct 2021 20:46:10 -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:mime-version :content-transfer-encoding; bh=kjJP3DimDgks7hWDrA8JwS8YTX2Y7gTetS5OZvY1EDA=; b=XkNolsPY2aLe5iHSBVHU7zuSwZI5K1N6LxW+iNCjIq+Xm8mqishckErEdVXXh8fRPG XRpYW8wIiDqOwxBqM1KEHEzQmmW4E7yev9AgMWH9frtneXFcKC8lto0Y7hdLGie0JNtM LG8VcQv9D2DrpFEICnrzm/pFMQDq1JMunRAz/Q2U1WEE8G399/shavANVFouAygTX6af BuwpOQKBbgS1I1kwl7DART0KFbcbcXlj4XLpDEibwSgpYlhL3HqIyWElt19JIvIU+nHD P3CGvkGjuDQ8z9pK10I3yfRCLEgT2qj0n7kIDdNJy441n+sLCMpCPQA+4lcLm3ATEzfO XIyQ== 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:mime-version :content-transfer-encoding; bh=kjJP3DimDgks7hWDrA8JwS8YTX2Y7gTetS5OZvY1EDA=; b=qiisi6wJ4tlESEZ0JNvMjVEnOi0Jnpc/s0bVZWLvCYzeZU0dTT3rUNUzXN3YQmFGQL yMmObMzL8oVUGQhm5UgsmWFYDObf1LJ9Z+UbMPD2f9Kv9dic/xnVhrtNG2OKeXXpM1jC NkBMZdf1oqarwArDTQzAfkPhyflct26IeH4SGPGsTf5K+ZvhK+cH37NvPXmSI9j0Bh3j IyPjhJ6JvYb3+r/DDbFxAxpj13dloIB5S1qJeiP3A7FUSoqPKTkrpT5axVXnP0dI2vwF xGnU9MO5JCvuS1ZCC7kEX5lHbwnU5gefKuUaqNnbfKOp2s2/YN2xfgWQJOQ03GNCjEcJ hdsw== X-Gm-Message-State: AOAM533vf9me/86+X9sdWCGyA/f62QQ58cDkLveVcC6WvlLC0CoANqWA 9HJS1aQ2xZFX3+9rjuVfJls= X-Google-Smtp-Source: ABdhPJzlXA7n8PGW6KinCgDiW/UW8WlyOKxBrHKKzC/9Qdmta+x5F7RytimxpAqMnXISuer831vMyQ== X-Received: by 2002:a17:90b:1e49:: with SMTP id pi9mr3684666pjb.144.1634787970627; Wed, 20 Oct 2021 20:46:10 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id r25sm3454254pge.61.2021.10.20.20.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:46:10 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 10/15] tools/lib/perf: use TASK_COMM_LEN_16 instead of hard-coded 16 Date: Thu, 21 Oct 2021 03:45:58 +0000 Message-Id: <20211021034603.4458-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use TASK_COMM_LEN_16 instead of hard-coded 16 to make it more grepable. The comm is set in perf_event__prepare_comm(), which makes the comm always a nul terminated string, so we don't worry about whether it will be truncated or not. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- tools/lib/perf/include/perf/event.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h index 4d0c02ba3f7d..ab22b4e570c6 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -6,6 +6,7 @@ #include #include #include +#include #include /* pid_t */ #define event_contains(obj, mem) ((obj).header.size > offsetof(typeof(obj), mem)) @@ -47,7 +48,7 @@ struct perf_record_mmap2 { struct perf_record_comm { struct perf_event_header header; __u32 pid, tid; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; struct perf_record_namespaces { @@ -291,7 +292,7 @@ struct perf_record_itrace_start { struct perf_record_thread_map_entry { __u64 pid; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; struct perf_record_thread_map { From patchwork Thu Oct 21 03:45:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12573737 X-Patchwork-Delegate: bpf@iogearbox.net 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 82B6EC433EF for ; Thu, 21 Oct 2021 03:47:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 605F1610A1 for ; Thu, 21 Oct 2021 03:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231764AbhJUDtn (ORCPT ); Wed, 20 Oct 2021 23:49:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbhJUDtT (ORCPT ); Wed, 20 Oct 2021 23:49:19 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8707EC06177E; Wed, 20 Oct 2021 20:46:12 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id oa12-20020a17090b1bcc00b0019f715462a8so3917100pjb.3; Wed, 20 Oct 2021 20:46:12 -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=WXJPrQ9678Se3QG+Xzf+zJqr3rYn2faOseef/yOHc9c=; b=F9u5C9s3ym5Y6yHJdNnaGcLBjH3jiTPlUN4K6C5NADSio2vbHZjtkjQ7QDQ6WJkxZr E1nHY+LOkeDyQkDWJPB9TmDib8PE0wH3eBdSd9/6iqT4ubqDBYp+ncllx2O8gu76QCCC XNIeFFaXU2akBiA8Q8DCm0gn0jn4WQ+iZ9Csd6bMtSgR/8y0qTRX12dNrTSjEEDfHQsr B6zSum0WYir9tEZjoAusoDDlb6tooQ2c6jo+Vjow6snYDnI574TZ5WKJIshqENQHcVTD AiwQ58fZHmrYZY3NPh5yK9cjX/V5j5ccGzc8oMi9Jig0xaHVXtquw1fbQV1GgTPscacg iK1w== 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=WXJPrQ9678Se3QG+Xzf+zJqr3rYn2faOseef/yOHc9c=; b=qUvVQYYEHj8Z/4vQ7qa/QBYXTG837aQIaA8I+AkjwzeR+Rd39ay9661Gqb0IFy/jl1 Od5w0rNdDPyT6Pq9OmA8pi/1SkdlvM2by/Dw6g4botlR7KuP1GoHoI4br5j9YDfcPJgK 3uGhBHrDaFKZgOuXdprMbLutC9xcF8OPfEwVjswI9Q8Ug9+WdSSp+fcV0dcs2UWLfXQl 2F0WeWVjYXaPg6yDI8uGkPs0hGVRfRKjcU/VFPhG39KlQOg53heqbKdvtjj7/yP3YTSo xCIcr2foaXjF+GQmyTKhRNBGl0AhzCGUctSRvjqVcg/7cbZfdPoXk2ItLXe2Tlne7EAa 8ehA== X-Gm-Message-State: AOAM5322aDoqHhjPUK3EtyCtcXI+oxAtq/37LN0107b7PKZtaKeE2cBn QQ9/VO6zt3bO7M+AaqXj5YdCN/FuZrM6EaLumYQGoA== X-Google-Smtp-Source: ABdhPJykQ537g0Oc0Tzo+SeeZAiRW14jcpCkkPvop9JWIPJg+4P2JqkOJYt2+D8aFwudaJZHzI9I/A== X-Received: by 2002:a17:902:c401:b0:13e:f5f2:f852 with SMTP id k1-20020a170902c40100b0013ef5f2f852mr2939252plk.29.1634787972119; Wed, 20 Oct 2021 20:46:12 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id r25sm3454254pge.61.2021.10.20.20.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:46:11 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 11/15] tools/bpf/bpftool: use TASK_COMM_LEN_16 instead of hard-coded 16 Date: Thu, 21 Oct 2021 03:45:59 +0000 Message-Id: <20211021034603.4458-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034603.4458-1-laoar.shao@gmail.com> References: <20211021034603.4458-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Use TASK_COMM_LEN_16 instead of hard-coded 16 to make it more grepable. It uses bpf_probe_read_kernel() to get task comm, which may return a string without nul terminator. We should use bpf_probe_read_kernel_str() instead. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- tools/bpf/bpftool/Makefile | 1 + tools/bpf/bpftool/main.h | 3 ++- tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 4 ++-- tools/bpf/bpftool/skeleton/pid_iter.h | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index d73232be1e99..33fbde84993c 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile @@ -164,6 +164,7 @@ $(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF) $(QUIET_CLANG)$(CLANG) \ -I$(if $(OUTPUT),$(OUTPUT),.) \ -I$(srctree)/tools/include/uapi/ \ + -I$(srctree)/tools/include/ \ -I$(LIBBPF_PATH) \ -I$(srctree)/tools/lib \ -g -O2 -Wall -target bpf -c $< -o $@ && $(LLVM_STRIP) -g $@ diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index 90caa42aac4c..5efa27188f68 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -124,7 +125,7 @@ struct obj_refs_table { struct obj_ref { int pid; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; struct obj_refs { 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; diff --git a/tools/bpf/bpftool/skeleton/pid_iter.h b/tools/bpf/bpftool/skeleton/pid_iter.h index 5692cf257adb..675b2916567e 100644 --- a/tools/bpf/bpftool/skeleton/pid_iter.h +++ b/tools/bpf/bpftool/skeleton/pid_iter.h @@ -3,10 +3,12 @@ #ifndef __PID_ITER_H #define __PID_ITER_H +#include + struct pid_iter_entry { __u32 id; int pid; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; #endif From patchwork Thu Oct 21 03:46:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12573735 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 77774C433F5 for ; Thu, 21 Oct 2021 03:47:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F9F460F57 for ; Thu, 21 Oct 2021 03:47:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231712AbhJUDtl (ORCPT ); Wed, 20 Oct 2021 23:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231315AbhJUDtT (ORCPT ); Wed, 20 Oct 2021 23:49:19 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DAC6C0613E3; Wed, 20 Oct 2021 20:46:14 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id np13so3914436pjb.4; Wed, 20 Oct 2021 20:46:14 -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=vH95WB7SHuZl+OHfTyscOsIJK4xnc4RRJ6+oOMiH9U0=; b=ONN6vvFd0ns96u6331CD6HkkWYCbEU6TjsbPJ/24mbKNA6tr5q7qQotTaj8Mnq0Oy/ 6sHAEY7EqLq8oowlubIxypFZHPuE221IyMHaK3Br1kteZmDSKJJxHc7yShnPNp6y5ert DQ9sucfTbC7xUjxwz/uBe8mgDdnYdYwbmICO8PpdsJknN+8LvXa9588A3h1sOOfVddsq HJ/QWQ688t81M+UOu/cITaRZppOeIbnp/OdAgruqOESddU5RRuoIjMpHMs4hGex9OcxC AnTMUfzgjE3fUID+dc4UxZHTEEpEIryazqNptQ4gjH8lRicgjPg/fqUJna6uq7HSds// pShA== 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=vH95WB7SHuZl+OHfTyscOsIJK4xnc4RRJ6+oOMiH9U0=; b=Tjwni8ZV/O1pdiOrsO17doTuphaq4J6RKG4Er8pz3l4HOIRtad4t/hyqQ1Ub0yi6dX +z6Aa1BaqBXNAocJg3POO1yODFd+EWoNGyWLMIhoyVLjiJxtPh8SxjIEEinm+Eoar1LN U9+FnUDa8zzJMypm1cwkkpOVqpQ/MwKtt8JYEUV3zsDyXsNPzCcp3w9U0256LwCeSRY0 kRp6ffMj+XtY72g1gzdoI5WSZtfEQ6xBvarrHcTVYALBfp28msqG3QAm33h/QLiK4fWd M5r0Xl6QRqQtpCm05wgB/ketr9FHPK9foRISM8dGOi7G5DGl9mpUDkmMEPklWd68meXe AcJA== X-Gm-Message-State: AOAM533YmK7v7iLyToshWxcvhuYqoiUnX9KGb2cT/+g/pFxynWyl2SlG zGC3e/NnM4jbsRFSsWtlMD8= X-Google-Smtp-Source: ABdhPJzaD6egSTgYDO3PO9pJHsve5z8E67H2laSTVUCwVC2kSTVI+Cy7/6mY2fEzIv/YbfiYagnsDA== X-Received: by 2002:a17:90b:4a49:: with SMTP id lb9mr3484246pjb.85.1634787973637; Wed, 20 Oct 2021 20:46:13 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id r25sm3454254pge.61.2021.10.20.20.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:46:13 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 12/15] tools/perf/test: make perf test adopt to task comm size change Date: Thu, 21 Oct 2021 03:46:00 +0000 Message-Id: <20211021034603.4458-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034603.4458-1-laoar.shao@gmail.com> References: <20211021034603.4458-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. Now that task comm can have a different size, then the test should accept the two sizes as possible and pass if it is 16 or 24. In order to do that, a new macro TASK_COMM_LEN_24 is introduced. 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: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- tools/include/linux/sched/task.h | 1 + tools/perf/tests/evsel-tp-sched.c | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/include/linux/sched/task.h b/tools/include/linux/sched/task.h index 7657dd3e0e02..da49ac983ac6 100644 --- a/tools/include/linux/sched/task.h +++ b/tools/include/linux/sched/task.h @@ -2,5 +2,6 @@ #define _TOOLS_PERF_LINUX_SCHED_TASK_H #define TASK_COMM_LEN_16 16 +#define TASK_COMM_LEN_24 24 #endif /* _TOOLS_PERF_LINUX_SCHED_TASK_H */ diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c index f9e34bd26cf3..cf4e0472e29e 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_24, 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_24, 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_24, false)) ret = -1; if (evsel__test_field(evsel, "pid", 4, true)) From patchwork Thu Oct 21 03:46:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12573741 X-Patchwork-Delegate: bpf@iogearbox.net 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 B645DC433FE for ; Thu, 21 Oct 2021 03:47:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A22FC610A1 for ; Thu, 21 Oct 2021 03:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbhJUDty (ORCPT ); Wed, 20 Oct 2021 23:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231428AbhJUDtY (ORCPT ); Wed, 20 Oct 2021 23:49:24 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 900E2C0613E5; Wed, 20 Oct 2021 20:46:15 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id m26so4705366pff.3; Wed, 20 Oct 2021 20:46:15 -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=vw+8P3h/cd/qdfXTUysYQI10wuP/awsRFjFZVZ6oyuo=; b=FMk+mSWZRkjJQwseuk8LuJWlfa6hE1iUkD0XgEf2G93U6t3EhkD1LOvFkjrII0gToC qV5PZXzAqDzv3bmwtO4AE/iFpFnotRZMWoXEOMIHJbSWOQGqr2c3HXRAlFVTp8Tan0Lt 619AwmGCWSCchYMMxt9pggqsvFenPNtHj4O+9gjyxy8OjhMV75K+TwT/EbLwxaRG79sp aWfOwTBuILzqvVmSxE/axHtuIk7wL+1bQeET+asn9EAI9o8Sua0nP05zbzNTqWWVMgsA 04tTJlO7/GqiCWGwFxkBy4f47pnK+/K8/Z+9oUSFRnXyo/+PYICBquw9CMXggCqJbw+Y 1EYQ== 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=vw+8P3h/cd/qdfXTUysYQI10wuP/awsRFjFZVZ6oyuo=; b=z4yRADLnGnjAiWjexUKiDcL6OnWKdcl1Bbqi9EiTtOz36UN+qVuZ7TMcyQFo6yHldv 6Lg6qxei7foY/48JG70Z7NpT1de8PTTlJfk2YJWh10sqOfId9tMJoCTca4YJP5EDfHCZ GJQ8Oqe2ovDxzR/vsYCZYKblMYVBzAlj+sPWV6iVyxMGmThvBmQFCv5Bt5ybslqyL+Gn enQNVH21FFmloLxZsg/tUIPFIYCnXwba3xvbWxWKp/jXBGAf7oJYR2PcvfDZg083FJTV JNEtyxFQfMLDd5Vyo6IYRnUC7nT71GLvj9M8LhJkZvkN7JOyEoVs4c/nRpm2FOEheG0P Scsw== X-Gm-Message-State: AOAM533kl91Rl7slIfdBCgwmv19c72ljxpjgLwVwqX1b6s94mnCAsxdg vtpklM8562KaPGXQAR5ujPk= X-Google-Smtp-Source: ABdhPJxLAi5Iqc3NxwXMd+0UNO64e2DEucuOsA6dYSg9zt3oOOmStq+k5dJ+9t9vDHwIcwodmylMvg== X-Received: by 2002:a05:6a00:14cc:b0:44d:ebab:2e16 with SMTP id w12-20020a056a0014cc00b0044debab2e16mr2892729pfu.23.1634787975094; Wed, 20 Oct 2021 20:46:15 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id r25sm3454254pge.61.2021.10.20.20.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:46:14 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 13/15] tools/testing/selftests/bpf: use TASK_COMM_LEN_16 instead of hard-coded 16 Date: Thu, 21 Oct 2021 03:46:01 +0000 Message-Id: <20211021034603.4458-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034603.4458-1-laoar.shao@gmail.com> References: <20211021034603.4458-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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. Below is the detailed information, bpf_get_current_comm: progs/test_ringbuf.c progs/test_ringbuf_multi.c prctl: prog_tests/test_overhead.c prog_tests/trampoline_count.c bpf_core_read_str: progs/test_core_reloc_kernel.c progs/test_sk_storage_tracing.c We'd better replace the hard-coded 16 with TASK_COMM_LEN_16 to make it more grepable. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Kees Cook Cc: Al Viro Cc: Petr Mladek --- tools/testing/selftests/bpf/Makefile | 2 +- tools/testing/selftests/bpf/prog_tests/ringbuf.c | 3 ++- tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c | 3 ++- .../testing/selftests/bpf/prog_tests/sk_storage_tracing.c | 3 ++- tools/testing/selftests/bpf/prog_tests/test_overhead.c | 3 ++- tools/testing/selftests/bpf/prog_tests/trampoline_count.c | 3 ++- tools/testing/selftests/bpf/progs/profiler.h | 7 ++++--- tools/testing/selftests/bpf/progs/profiler.inc.h | 8 ++++---- tools/testing/selftests/bpf/progs/pyperf.h | 4 ++-- tools/testing/selftests/bpf/progs/strobemeta.h | 6 +++--- .../testing/selftests/bpf/progs/test_core_reloc_kernel.c | 3 ++- tools/testing/selftests/bpf/progs/test_ringbuf.c | 3 ++- tools/testing/selftests/bpf/progs/test_ringbuf_multi.c | 3 ++- .../testing/selftests/bpf/progs/test_sk_storage_tracing.c | 5 +++-- tools/testing/selftests/bpf/progs/test_skb_helpers.c | 5 ++--- tools/testing/selftests/bpf/progs/test_stacktrace_map.c | 5 +++-- tools/testing/selftests/bpf/progs/test_tracepoint.c | 5 +++-- 17 files changed, 41 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 799b88152e9e..5e72d783d3fe 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -279,7 +279,7 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ - -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ + -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) -I${TOOLSINCDIR} \ -I$(abspath $(OUTPUT)/../usr/include) CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c index 4706cee84360..ac82d57c09dc 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "test_ringbuf.lskel.h" #define EDONE 7777 @@ -22,7 +23,7 @@ struct sample { int pid; int seq; long value; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; static int sample_cnt; diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c index 167cd8a2edfd..f0748305ffd6 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c @@ -2,6 +2,7 @@ #define _GNU_SOURCE #include #include +#include #include "test_ringbuf_multi.skel.h" static int duration = 0; @@ -10,7 +11,7 @@ struct sample { int pid; int seq; long value; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; static int process_sample(void *ctx, void *data, size_t len) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_storage_tracing.c b/tools/testing/selftests/bpf/prog_tests/sk_storage_tracing.c index 2b392590e8ca..f77d3b44ed35 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_storage_tracing.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_storage_tracing.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "test_progs.h" #include "network_helpers.h" #include "test_sk_storage_trace_itself.skel.h" @@ -15,7 +16,7 @@ struct sk_stg { __u32 pid; __u32 last_notclose_state; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; static struct test_sk_storage_tracing *skel; diff --git a/tools/testing/selftests/bpf/prog_tests/test_overhead.c b/tools/testing/selftests/bpf/prog_tests/test_overhead.c index 123c68c1917d..133987217f57 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_overhead.c +++ b/tools/testing/selftests/bpf/prog_tests/test_overhead.c @@ -4,6 +4,7 @@ #include #include #include +#include #define MAX_CNT 100000 @@ -67,7 +68,7 @@ void test_test_overhead(void) struct bpf_object *obj; struct bpf_link *link; int err, duration = 0; - char comm[16] = {}; + char comm[TASK_COMM_LEN_16] = {}; if (CHECK_FAIL(prctl(PR_GET_NAME, comm, 0L, 0L, 0L))) return; diff --git a/tools/testing/selftests/bpf/prog_tests/trampoline_count.c b/tools/testing/selftests/bpf/prog_tests/trampoline_count.c index d7f5a931d7f3..4765b2ebd219 100644 --- a/tools/testing/selftests/bpf/prog_tests/trampoline_count.c +++ b/tools/testing/selftests/bpf/prog_tests/trampoline_count.c @@ -3,6 +3,7 @@ #include #include #include +#include #define MAX_TRAMP_PROGS 38 @@ -50,7 +51,7 @@ void test_trampoline_count(void) int err, i = 0, duration = 0; struct bpf_object *obj; struct bpf_link *link; - char comm[16] = {}; + char comm[TASK_COMM_LEN_16] = {}; /* attach 'allowed' trampoline programs */ for (i = 0; i < MAX_TRAMP_PROGS; i++) { diff --git a/tools/testing/selftests/bpf/progs/profiler.h b/tools/testing/selftests/bpf/progs/profiler.h index 3bac4fdd4bdf..7ffc801d790b 100644 --- a/tools/testing/selftests/bpf/progs/profiler.h +++ b/tools/testing/selftests/bpf/progs/profiler.h @@ -2,7 +2,8 @@ /* Copyright (c) 2020 Facebook */ #pragma once -#define TASK_COMM_LEN 16 +#include + #define MAX_ANCESTORS 4 #define MAX_PATH 256 #define KILL_TARGET_LEN 64 @@ -14,7 +15,7 @@ #define MAX_FILEPATH_LENGTH (MAX_PATH_DEPTH * MAX_PATH) #define MAX_CGROUPS_PATH_DEPTH 8 -#define MAX_METADATA_PAYLOAD_LEN TASK_COMM_LEN +#define MAX_METADATA_PAYLOAD_LEN TASK_COMM_LEN_16 #define MAX_CGROUP_PAYLOAD_LEN \ (MAX_PATH * 2 + (MAX_PATH * MAX_CGROUPS_PATH_DEPTH)) @@ -25,7 +26,7 @@ (MAX_METADATA_PAYLOAD_LEN + MAX_CGROUP_PAYLOAD_LEN + CTL_MAXNAME + MAX_PATH) #define MAX_KILL_PAYLOAD_LEN \ - (MAX_METADATA_PAYLOAD_LEN + MAX_CGROUP_PAYLOAD_LEN + TASK_COMM_LEN + \ + (MAX_METADATA_PAYLOAD_LEN + MAX_CGROUP_PAYLOAD_LEN + TASK_COMM_LEN_16 + \ KILL_TARGET_LEN) #define MAX_EXEC_PAYLOAD_LEN \ diff --git a/tools/testing/selftests/bpf/progs/profiler.inc.h b/tools/testing/selftests/bpf/progs/profiler.inc.h index 4896fdf816f7..fad39075e5ce 100644 --- a/tools/testing/selftests/bpf/progs/profiler.inc.h +++ b/tools/testing/selftests/bpf/progs/profiler.inc.h @@ -344,9 +344,9 @@ static INLINE void* populate_var_metadata(struct var_metadata_t* metadata, metadata->start_time = BPF_CORE_READ(task, start_time); metadata->comm_length = 0; - size_t comm_length = bpf_core_read_str(payload, TASK_COMM_LEN, &task->comm); + size_t comm_length = bpf_core_read_str(payload, TASK_COMM_LEN_16, &task->comm); barrier_var(comm_length); - if (comm_length <= TASK_COMM_LEN) { + if (comm_length <= TASK_COMM_LEN_16) { barrier_var(comm_length); metadata->comm_length = comm_length; payload += comm_length; @@ -648,9 +648,9 @@ int raw_tracepoint__sched_process_exit(void* ctx) kill_data->kill_target_name_length = 0; kill_data->kill_target_cgroup_proc_length = 0; - size_t comm_length = bpf_core_read_str(payload, TASK_COMM_LEN, &task->comm); + size_t comm_length = bpf_core_read_str(payload, TASK_COMM_LEN_16, &task->comm); barrier_var(comm_length); - if (comm_length <= TASK_COMM_LEN) { + if (comm_length <= TASK_COMM_LEN_16) { barrier_var(comm_length); kill_data->kill_target_name_length = comm_length; payload += comm_length; diff --git a/tools/testing/selftests/bpf/progs/pyperf.h b/tools/testing/selftests/bpf/progs/pyperf.h index 2fb7adafb6b6..05cb40268887 100644 --- a/tools/testing/selftests/bpf/progs/pyperf.h +++ b/tools/testing/selftests/bpf/progs/pyperf.h @@ -6,11 +6,11 @@ #include #include #include +#include #include #define FUNCTION_NAME_LEN 64 #define FILE_NAME_LEN 128 -#define TASK_COMM_LEN 16 typedef struct { int PyThreadState_frame; @@ -43,7 +43,7 @@ typedef struct { typedef struct { uint32_t pid; uint32_t tid; - char comm[TASK_COMM_LEN]; + char comm[TASK_COMM_LEN_16]; int32_t kernel_stack_id; int32_t user_stack_id; bool thread_current; diff --git a/tools/testing/selftests/bpf/progs/strobemeta.h b/tools/testing/selftests/bpf/progs/strobemeta.h index 7de534f38c3f..acfe929fd32d 100644 --- a/tools/testing/selftests/bpf/progs/strobemeta.h +++ b/tools/testing/selftests/bpf/progs/strobemeta.h @@ -8,12 +8,12 @@ #include #include #include +#include #include typedef uint32_t pid_t; struct task_struct {}; -#define TASK_COMM_LEN 16 #define PERF_MAX_STACK_DEPTH 127 #define STROBE_TYPE_INVALID 0 @@ -189,7 +189,7 @@ struct strobemeta_payload { struct strobelight_bpf_sample { uint64_t ktime; - char comm[TASK_COMM_LEN]; + char comm[TASK_COMM_LEN_16]; pid_t pid; int user_stack_id; int kernel_stack_id; @@ -520,7 +520,7 @@ int on_event(struct pt_regs *ctx) { return 0; /* this will never happen */ sample->pid = pid; - bpf_get_current_comm(&sample->comm, TASK_COMM_LEN); + bpf_get_current_comm(&sample->comm, TASK_COMM_LEN_16); ktime_ns = bpf_ktime_get_ns(); sample->ktime = ktime_ns; diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c b/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c index 145028b52ad8..33bf5b1058e5 100644 --- a/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c +++ b/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,7 @@ struct core_reloc_kernel_output { struct task_struct { int pid; int tgid; - char comm[16]; + char comm[TASK_COMM_LEN_16]; struct task_struct *group_leader; }; diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf.c b/tools/testing/selftests/bpf/progs/test_ringbuf.c index eaa7d9dba0be..15bb2087371e 100644 --- a/tools/testing/selftests/bpf/progs/test_ringbuf.c +++ b/tools/testing/selftests/bpf/progs/test_ringbuf.c @@ -2,6 +2,7 @@ // Copyright (c) 2020 Facebook #include +#include #include char _license[] SEC("license") = "GPL"; @@ -10,7 +11,7 @@ struct sample { int pid; int seq; long value; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; struct { diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c index 197b86546dca..88c7f65a8f3f 100644 --- a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c +++ b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c @@ -2,6 +2,7 @@ // Copyright (c) 2020 Facebook #include +#include #include char _license[] SEC("license") = "GPL"; @@ -10,7 +11,7 @@ struct sample { int pid; int seq; long value; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; struct ringbuf_map { diff --git a/tools/testing/selftests/bpf/progs/test_sk_storage_tracing.c b/tools/testing/selftests/bpf/progs/test_sk_storage_tracing.c index 8e94e5c080aa..cd965e9f22f0 100644 --- a/tools/testing/selftests/bpf/progs/test_sk_storage_tracing.c +++ b/tools/testing/selftests/bpf/progs/test_sk_storage_tracing.c @@ -2,6 +2,7 @@ /* Copyright (c) 2020 Facebook */ #include +#include #include #include #include @@ -9,7 +10,7 @@ struct sk_stg { __u32 pid; __u32 last_notclose_state; - char comm[16]; + char comm[TASK_COMM_LEN_16]; }; struct { @@ -27,7 +28,7 @@ struct { __type(value, int); } del_sk_stg_map SEC(".maps"); -char task_comm[16] = ""; +char task_comm[TASK_COMM_LEN_16] = ""; SEC("tp_btf/inet_sock_set_state") int BPF_PROG(trace_inet_sock_set_state, struct sock *sk, int oldstate, diff --git a/tools/testing/selftests/bpf/progs/test_skb_helpers.c b/tools/testing/selftests/bpf/progs/test_skb_helpers.c index bb3fbf1a29e3..cbe134eab8fe 100644 --- a/tools/testing/selftests/bpf/progs/test_skb_helpers.c +++ b/tools/testing/selftests/bpf/progs/test_skb_helpers.c @@ -1,10 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only #include "vmlinux.h" +#include #include #include -#define TEST_COMM_LEN 16 - struct { __uint(type, BPF_MAP_TYPE_CGROUP_ARRAY); __uint(max_entries, 1); @@ -18,7 +17,7 @@ SEC("classifier/test_skb_helpers") int test_skb_helpers(struct __sk_buff *skb) { struct task_struct *task; - char comm[TEST_COMM_LEN]; + char comm[TASK_COMM_LEN_16]; __u32 tpid; task = (struct task_struct *)bpf_get_current_task(); diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c index 00ed48672620..e4938b3cdf7a 100644 --- a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c +++ b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c @@ -2,6 +2,7 @@ // Copyright (c) 2018 Facebook #include +#include #include #ifndef PERF_MAX_STACK_DEPTH @@ -41,11 +42,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_16]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN_16]; 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..eb6e84ebf704 100644 --- a/tools/testing/selftests/bpf/progs/test_tracepoint.c +++ b/tools/testing/selftests/bpf/progs/test_tracepoint.c @@ -2,16 +2,17 @@ // 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_16]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN_16]; int next_pid; int next_prio; }; From patchwork Thu Oct 21 03:46:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12573739 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 9B199C433FE for ; Thu, 21 Oct 2021 03:47:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8150861038 for ; Thu, 21 Oct 2021 03:47:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231803AbhJUDtu (ORCPT ); Wed, 20 Oct 2021 23:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbhJUDtY (ORCPT ); Wed, 20 Oct 2021 23:49:24 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DC8BC0613E6; Wed, 20 Oct 2021 20:46:17 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id i1so958921plr.13; Wed, 20 Oct 2021 20:46:17 -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=0yM3sBzVJixym6Pyyba7mfqYZoAEZb2k8KizyPSP7kg=; b=RBw5omD4rTgpJrDE/tF+65u3aiUUhbDOjoxYbOUTHLFsfzRCE1qLcza3dSQSuVNI9x yF4Rv2/3XR1+nsVOwkxJWIeuqgR8C3VcwQcCdU+q+hrFIAEEkfojFwHV5SSDlODMV7wD Mg5hYwDDJUQS44dzlc46KJxWu33Q+ADcSFvpUJBAomHNtUFnd8YHwF+ThysyEXXq9PJf BemE8OTfob3ebmojHzE0pKT/udvY799lkaP2MVbPwq7KVGJQ1w03aj0fSkmeod98u3Om gIH2TvQtYBYmddoWcGYRYg8zpNyFg0MTuSO4IRoDXuzXdLDJcsFbabi0At9po1agLjxj gNQQ== 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=0yM3sBzVJixym6Pyyba7mfqYZoAEZb2k8KizyPSP7kg=; b=izgIHKy7yJ4Nzs6J5w9kzu8lnBFIax+A6dO3vMqwLXedzP690Fgin6hcmsvwFtZ218 +h5z/mK0N2+mgO8EWyEBf8HBi/1enSmUUY8q9RfAx6+B0sFtgg4AAepLGzobKYpIlXrU HrdksSQBJmOHOsqVQQc63DgEQ2o3BY5uq9KGl8p+ifusB4Ac7F+n13D7eIx0Cj8l3uMZ UnKb4xk37WeAaTBxEBmrmo011cjSlPW+WJHLF0IUoxbO2n5FH4ma4xcYpLwSqUSUldDm FMHKbxjkpziAZcOo75LDlWCPsNcLTR81f/w1FaAKGj2J9VMd85A9DU5Vwi6oTuC9HVEw YHTQ== X-Gm-Message-State: AOAM530qiLSdCq1ZM9ZMZMWa+SM1hVVb0jJU3INahcsSTNcZ+cISL/0x eraDNHWPG+4k3oTVUN2L/VE= X-Google-Smtp-Source: ABdhPJxUL9qjB7igAdeOyZKwIJlugL1A0condl4sE5mTHamDXIGLy5/Lf+hpbqa+DOy9OirQoWCv4A== X-Received: by 2002:a17:90a:2a0d:: with SMTP id i13mr3517622pjd.166.1634787976727; Wed, 20 Oct 2021 20:46:16 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id r25sm3454254pge.61.2021.10.20.20.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:46:16 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 14/15] sched.h: extend task comm from 16 to 24 for CONFIG_BASE_FULL Date: Thu, 21 Oct 2021 03:46:02 +0000 Message-Id: <20211021034603.4458-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034603.4458-1-laoar.shao@gmail.com> References: <20211021034603.4458-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. This patch extends the size of task comm to 24 bytes, which is the same length with workqueue's, for the CONFIG_BASE_FULL case. And for the CONFIG_BASE_SMALL case, the size of task comm is still kept as 16 bytes. After this patchset, 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 Suggested-by: Petr Mladek Suggested-by: Steven Rostedt Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Petr Mladek --- include/linux/sched.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 62d5b30d310c..fcb4bc97f95c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -274,10 +274,17 @@ struct task_group; #define get_current_state() READ_ONCE(current->__state) -/* To replace the old hard-coded 16 */ -#define TASK_COMM_LEN_16 16 +/* Also to replace the old hard-coded 16 */ +#define TASK_COMM_LEN_16 16 +#define TASK_COMM_LEN_24 24 + + /* Task command name length: */ -#define TASK_COMM_LEN 16 +#if CONFIG_BASE_SMALL +#define TASK_COMM_LEN TASK_COMM_LEN_16 +#else +#define TASK_COMM_LEN TASK_COMM_LEN_24 +#endif extern void scheduler_tick(void); From patchwork Thu Oct 21 03:46:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12573743 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 90832C433F5 for ; Thu, 21 Oct 2021 03:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79F5D61038 for ; Thu, 21 Oct 2021 03:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbhJUDt5 (ORCPT ); Wed, 20 Oct 2021 23:49:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231424AbhJUDtY (ORCPT ); Wed, 20 Oct 2021 23:49:24 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDFB9C061753; Wed, 20 Oct 2021 20:46:18 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id r2so24361012pgl.10; Wed, 20 Oct 2021 20:46:18 -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=Mg/W5W6l0pcytUDlQ1aNCJcnr1/VYvxAUJDYpkY9L/c=; b=nCBNOEdF81o2V/ZOVUdV514sp3NllC5LbtK99UBMXWooz5rjDlFETHpYTA8A8T88Ip tAQjqAfaNMXWgtSyT+9Lje7Sn6b/fM6dUq96+o8dZ6TEn+3fpaggTvmtiO1ptoCNfgw+ manf4GP+UAzTMRty33VBcUTjT6fxv2Xfusd7xEWkaShtHDiiTZ+OgCuVcCLaZDPYnhig YQFosMyYmS+c3bfNM/Y/F+aoj9wESBVhLNcV4mRJ3Wv1OuxxPQJDbga588ePtif5m3KI QT68h9quKWtAvhhjk2DwlXE7M3Zvj6Vxbhf4F3KyOiAEpX+Wk/Wr6LvMD2TrccAaHZjq JPKA== 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=Mg/W5W6l0pcytUDlQ1aNCJcnr1/VYvxAUJDYpkY9L/c=; b=m8EsTHcWtPm9nsIlZ9TaVxwdDb+x7Gm1qD3mVrugivc1OwSdwXkFfABM2n+//Hbmp9 kSRpWWA8bUWg+PNJs2FmZVxQNI1JF/NNFSf3DzIria6Da3WjViMRUO8OsVp9dRldjCds F8Qr2+/JBXniN6q681szsKnnU/dyyp8BZAbmionzFjK0rtQU/yRfjW167FKuUtsD26z7 T6y7mLikcODPm7tQiO9yolECChFfngJkMY5IUVm6QYZIKWUKLwvsTdvX0CmZEY+zfuyQ CDlINzjmc/vGyHYVX+xmkcT2HPfntGveYWFrJjP2EDOoYM1q4wgWjMx4M7zsIfSg82xS /9Yg== X-Gm-Message-State: AOAM531dRpDTcoFv/BB0E3T9NAGtO7/3YLWN7sbbh6YY6vobIE6BDuad P3g2qtgEmoCzZcnV+rS2uks= X-Google-Smtp-Source: ABdhPJw5Fj3ty7sa//4egXRyvTSsUWdMNkokVd4ZY+8Yz400yvz6Ngl1ciRpem81fOw6ilYWzxyVRQ== X-Received: by 2002:a05:6a00:23d6:b0:44d:8426:e2bb with SMTP id g22-20020a056a0023d600b0044d8426e2bbmr2824167pfc.30.1634787978484; Wed, 20 Oct 2021 20:46:18 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id r25sm3454254pge.61.2021.10.20.20.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:46:17 -0700 (PDT) From: Yafang Shao To: 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, akpm@linux-foundation.org, 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao Subject: [PATCH v5 15/15] kernel/kthread: show a warning if kthread's comm is truncated Date: Thu, 21 Oct 2021 03:46:03 +0000 Message-Id: <20211021034603.4458-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211021034603.4458-1-laoar.shao@gmail.com> References: <20211021034603.4458-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Show a warning if task comm is truncated. Below is the result of my test case: truncated kthread comm:I-am-a-kthread-with-lon, pid:14 by 6 characters Suggested-by: Petr Mladek Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro 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..46b924c92078 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.