From patchwork Mon Oct 25 08:33:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12581055 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 19777C43217 for ; Mon, 25 Oct 2021 08:33:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 025D460EE9 for ; Mon, 25 Oct 2021 08:33:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232238AbhJYIgL (ORCPT ); Mon, 25 Oct 2021 04:36:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231241AbhJYIgH (ORCPT ); Mon, 25 Oct 2021 04:36:07 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D5B0C061745; Mon, 25 Oct 2021 01:33:45 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id f11so10013309pfc.12; Mon, 25 Oct 2021 01:33:45 -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=tb2DLSHt7yEoDSj1xonLMAUM0KyNZsEaGyv5bBEUpu8=; b=oYlyi3lonUU6Fa8XZ2e7zj+Xij1FY4rsdKgLByteR1YoxJaXWn0b+9E04KwplgPwen Nsyc4c9ZtY3k38kLVKWr4UpYSbaABNZRdpSExH5nuGb3+YWWsIS4+YyBPSUGBFurjTCU E0r982qEh5Dd3WP8mqTWX1MQoiNzsPO0G0x9u8jvrqPNkmLCIxRNvLPQQZgXaoOfXaDN kaPzNZ1W1O5wHYsrZCyowbYAkbsOKKXpRCd6MsdvrN1ds01r0ejvZnHwygt9j9a35bCk Cf2hKPGffK2GWb7AtSjLShunf3C66hJNoQRYhRnelFTTOniybfDGnJeB/MIbgD338RDP Pnuw== 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=tb2DLSHt7yEoDSj1xonLMAUM0KyNZsEaGyv5bBEUpu8=; b=wqckCDcr1jjU34dQC58DeAXjOW9JF+zB9Reuxt3Q2vYidR1dBPL0nJQ9osXfXdY5c9 iKwS2vin+dPS/ku/5XtYJ7lkYgV5gn3dzrSK3u5+GENINVppXHxTj7T1nPheZ3s9rOgH KEQi4HfQhNYEvzkKrhbTTuvAe7vkIiSHU1BXufQBMypbcLIRCf/XSr4fqm1YKoJDZUEi TOr3ejRk+XVqDrQUWVRdki3fd8AoJFaRtoaxc63ip2KRuBm0QbX3vENqj7Z4AKTmnYNi rpW/a42dGAd9JpKh2tx5/6B0qbD5AAK2igUBcz+6jN2disaf7os0TEEOaRN23cFqByhF sbDA== X-Gm-Message-State: AOAM530tJ04N4Al+m67ayhw9Q8gSAABRKYuOXHlNidq2PMBn95pDN3cc f6GsyWfop0/4Ym2vziVrBSU= X-Google-Smtp-Source: ABdhPJww37Zh1A/cWqYLv8cApefSTpVITM+SVBpIEk1zj0/wZq+xUgY47FOrn91DuZ+bARyzae7T1A== X-Received: by 2002:a05:6a00:23d3:b0:44c:a67f:49af with SMTP id g19-20020a056a0023d300b0044ca67f49afmr17110818pfc.50.1635150824679; Mon, 25 Oct 2021 01:33:44 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:33:44 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 01/12] fs/exec: make __set_task_comm always set a nul ternimated string Date: Mon, 25 Oct 2021 08:33:04 +0000 Message-Id: <20211025083315.4752-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Make sure the string set to task comm is always nul ternimated. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek Reviewed-by: Kees Cook --- fs/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index a098c133d8d7..404156b5b314 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1224,7 +1224,7 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) { task_lock(tsk); trace_task_rename(tsk, buf); - strlcpy(tsk->comm, buf, sizeof(tsk->comm)); + strscpy_pad(tsk->comm, buf, sizeof(tsk->comm)); task_unlock(tsk); perf_event_comm(tsk, exec); } From patchwork Mon Oct 25 08:33:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12581057 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 408FDC433FE for ; Mon, 25 Oct 2021 08:33:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A54E61027 for ; Mon, 25 Oct 2021 08:33:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232292AbhJYIgP (ORCPT ); Mon, 25 Oct 2021 04:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232197AbhJYIgJ (ORCPT ); Mon, 25 Oct 2021 04:36:09 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BC5FC061767; Mon, 25 Oct 2021 01:33:47 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id t21so7414299plr.6; Mon, 25 Oct 2021 01:33:47 -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=7jKAATsl3Or1OXSx7HWzFCkHaZKf4EVahxCQwpQ+O5E=; b=TJLriZ5mdvjw59l3C40lhg68iy+fuuT/jguhTtjAocwEu+c8nhtiZgl51JsEcljfGU DB3lnJ+73ti9a7qpfCexwR+yJUi+FzWhAy/Jg0rkrHZb/wKiwVwjQbRFtHrD1sxqyLMB OusVpdCEsgFi/hiqfbaX0zl8ZaPLsq2cj5n0WWCGk1NvjnK0R8M+Y1OL61mO+BYHAQXo MRuuBVIY4v15HGw/VXe3XNBcdznsFM48gmgaB7qVcGfRpToafeCXSEZUlYNfYgwMdBcd OD9KcTYFsc9oIwkU6T+9hZWmv0cvSRpaQAB/pmkMdO5QHPU55muhXcsNQaKMj+pjvDmV RdTQ== 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=7jKAATsl3Or1OXSx7HWzFCkHaZKf4EVahxCQwpQ+O5E=; b=ka7pVgEobO+88Ww/l/FLPIMDqxn4hSsurEj+JczBFi/STIwD7ySk+T6k2UMbust6e+ E3lneSMo14kE4VAabdFUo5pp9nAzFHAFBlh+rbJNq9HrgE21dYFfnr3O6r1mRJ7A8ZvX zajhblX0FJpzhPbNxkAutQFrfJfJoo2ujjDzmBgMLJP2zSYB4MdXb4O8SVryByArEDag RmowrEPmmCWWa79tF4j14TYJZEy30r7+EzwtAr+a0KBXY39ACM5910kd/yYT44jj06wr dFuO6FZUrZUxOiN+Jc1bBpviyaAjq+qyO3MmmnBkgAIUsSs5YawB8FCy4pds+qytfdrQ 96Dg== X-Gm-Message-State: AOAM531D56anvOxY8WGcBBJlTv2RYx7AY7QBWRBYAUGwQxiMyhkw6qPd LDyBACyPlz4NFhHzlKUT6YQ= X-Google-Smtp-Source: ABdhPJzYTnld7M84SDgJqip1ULz6qBYAnLfyifxnrJWJrcZvxH4N4k1/v119JIj2PZtcu7zZWBQaxA== X-Received: by 2002:a17:90a:6788:: with SMTP id o8mr23634231pjj.53.1635150826928; Mon, 25 Oct 2021 01:33:46 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:33:46 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 02/12] fs/exec: make __get_task_comm always get a nul terminated string Date: Mon, 25 Oct 2021 08:33:05 +0000 Message-Id: <20211025083315.4752-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek Reviewed-by: Kees Cook --- 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 Mon Oct 25 08:33:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12581059 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 0E7BDC4332F for ; Mon, 25 Oct 2021 08:34:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECE7F604AC for ; Mon, 25 Oct 2021 08:33:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232361AbhJYIgT (ORCPT ); Mon, 25 Oct 2021 04:36:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232172AbhJYIgL (ORCPT ); Mon, 25 Oct 2021 04:36:11 -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 B3012C061764; Mon, 25 Oct 2021 01:33:49 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id m21so10178681pgu.13; Mon, 25 Oct 2021 01:33:49 -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=rF1WxMESVJWbA0KjHUw1EAC/hqp6WgyH56B9+/ool+Y=; b=csPDI4HJ67TdymQQcsFexEUPoDgg26NWwNi/rwWaHt/rnz379QkpJRSIHuq8TVEgYg ZhbZz64XqUIshqzzWpYvuq3gi3XxxDhHFGfddtvJpFHmPX4Ut0V3sSa/Q8tOv+R7Q/pp +iHi5bc3UQLFoHCxJWLvyS2xNk9NzBIV0OY66qa2bm4wUd2q2xY8k4OtVhtaks7dMIO8 KipeoYrJONCg77Yq+PAf7OmcVgY+dj6VBfnQMPDFXd9jjOWbgVTwxjQHhPU0in18pnyS 1LQLX3U+daG5LZVaEJyKTVgal4lNpD8KR1aG2Jy0XkNCJs+RLlFcIaBscjzcwQwCX8Ql KcXA== 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=rF1WxMESVJWbA0KjHUw1EAC/hqp6WgyH56B9+/ool+Y=; b=1gRDNdSvV0YdmoredQpeq3yrhZJlgpYG1o8iCs1bXm62nbsMq2jJA48l8tH4suDH0G D9b3iVgY7W5OUyt7NiITry5Yj769xBNyxTw075WlqIArqS1jKfFvkHz3tl96lHMm0oNQ aUhTJS79krY3i9PDUJ2l+Q6Nuzx3/p4BllWmjXyNqIQZrWV7uhw4k6RgZN/R879QDd9W D2yWYIXViRr75pT16UGrxiNzslaeQ9G5Z2QVvX82ou1ix11YbWJIOVlpWx4FJdexC0s2 R6CyLu5FhMxjuohsR46ZgllYYo6RRY/zd27EY3H9XNWrUdm2ho+gDDzLEFRps5t6XRzO 5F8A== X-Gm-Message-State: AOAM533NDU6wBCSMPmGcqjjmzWlAR8H8GHQiNF/PoeNhIWuoZ4ubNQxv Sbjkci9zjoDut4nrmBdc3c0= X-Google-Smtp-Source: ABdhPJzmR7B3F/oDzpPz7UArNu9RJcw2YYz6E4xdldXe9GqTF0sfz89yReHIXFFjXn32SUShtQ07fg== X-Received: by 2002:a63:1a0e:: with SMTP id a14mr12821120pga.195.1635150829344; Mon, 25 Oct 2021 01:33:49 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:33:48 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko , Vladimir Zapolskiy , David Howells Subject: [PATCH v6 03/12] drivers/connector: make connector comm always nul ternimated Date: Mon, 25 Oct 2021 08:33:06 +0000 Message-Id: <20211025083315.4752-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.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: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Vladimir Zapolskiy Cc: Peter Zijlstra Cc: Steven Rostedt Cc: David Howells Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- drivers/connector/cn_proc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 */ From patchwork Mon Oct 25 08:33:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12581061 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 5CDACC433F5 for ; Mon, 25 Oct 2021 08:34:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 469A361039 for ; Mon, 25 Oct 2021 08:34:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232450AbhJYIg0 (ORCPT ); Mon, 25 Oct 2021 04:36:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232201AbhJYIgO (ORCPT ); Mon, 25 Oct 2021 04:36:14 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98C46C061243; Mon, 25 Oct 2021 01:33:52 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id g184so10206201pgc.6; Mon, 25 Oct 2021 01:33:52 -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=UmL9mpq7ehorzv6mgqkv4FtNwEi5vXpR3ERUyc8B1Bw=; b=f163QO/wIMQJPdoOkjqjFlNKMvqBZPsmaXtbryyYsIponOQR+Wm55Kffl/PqBvwbrX 2/bBGcHDjPpzSIG3jHCU6R3yJhNS+wQbdOfhoARB4yOocKMk8a+JNUVgk+/tBmA4q/Dk l2yEM/9ONmEYqiekXtJh3uOggqoVLCw/FP+bgYRLjIi0LhlqKy097NOWqtKsk6NXpKS3 DpSR3iN0FMse4S3PFGXm4G87lI8Mmg9ix/Wnyy1UPCWTHShXVchuDPcZwYV22SwmY06V niK8f1/1wZOqhierpRxnaj0S4IqCJQpLRQvmAo27zHXjVn6dlNf1WWEL8El50f1yFTzK O1jQ== 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=UmL9mpq7ehorzv6mgqkv4FtNwEi5vXpR3ERUyc8B1Bw=; b=QH8bpyiTfJQeJIoEZJtyIOb3AZuufBPSn40DcZ3Cp4tti39Xr5X1BctRZGk4AqGU84 zC1giYJmM6cFC9OiKThr8yxrFfevr8e29gfVXlDhaMNjVBzVo8s9Bg4YkfPfq+L1eJ9u suuWwkBHyTSwHYAG/F0GKhxmTvmQe5IvHHf5OaRzhvPBTO5TRtruaT2CmmM3wC3CM/RJ +e0W5HZT5SoZYDC0+H0qkyb03nc0TVJ1AvNQzKF4Vyt55g1Eu3C3xNSYPJ9f4lbtDODl jH6v5jate7e4h0+SvPSy+IhXHZYuPGgV9PN9zrDXfC7FF03PXeXE2viiA6C4hh+Db369 SDVw== X-Gm-Message-State: AOAM530zJCpAJWg5/ZnWTLxu35wyJdrq1hrpJtiB/LBSVgqL0XkDmwZK MrnF4wcWq7pPeQNp97Xc+KM= X-Google-Smtp-Source: ABdhPJwx82IKjZxf23iOo5e3UwoMZbq9DUsUmXnmSmClvglJWBA7mwqyIOKzLfgPYkxV6YLTaw9Few== X-Received: by 2002:a63:3c5d:: with SMTP id i29mr9097063pgn.59.1635150831602; Mon, 25 Oct 2021 01:33:51 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:33:51 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 04/12] drivers/infiniband: make setup_ctxt always get a nul terminated task comm Date: Mon, 25 Oct 2021 08:33:07 +0000 Message-Id: <20211025083315.4752-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Use strscpy_pad() instead of strlcpy() to make the comm always nul terminated. As the comment above the hard-coded 16, we can replace it with TASK_COMM_LEN, then it will adopt to the comm size change. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek Acked-by: Dennis Dalessandro --- drivers/infiniband/hw/qib/qib.h | 2 +- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h index 9363bccfc6e7..a8e1c30c370f 100644 --- a/drivers/infiniband/hw/qib/qib.h +++ b/drivers/infiniband/hw/qib/qib.h @@ -196,7 +196,7 @@ struct qib_ctxtdata { pid_t pid; pid_t subpid[QLOGIC_IB_MAX_SUBCTXT]; /* same size as task_struct .comm[], command that opened context */ - char comm[16]; + char comm[TASK_COMM_LEN]; /* pkeys set by this use of this ctxt */ u16 pkeys[4]; /* so file ops can get at unit */ diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c index 63854f4b6524..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 Mon Oct 25 08:33: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: 12581063 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 9BF45C433FE for ; Mon, 25 Oct 2021 08:34:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B9B361039 for ; Mon, 25 Oct 2021 08:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232525AbhJYIgb (ORCPT ); Mon, 25 Oct 2021 04:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232302AbhJYIgQ (ORCPT ); Mon, 25 Oct 2021 04:36:16 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82836C061225; Mon, 25 Oct 2021 01:33:54 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id r2so10173803pgl.10; Mon, 25 Oct 2021 01:33:54 -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=kAjJkCSR5rLgc1ik/eORDjpCuJ13N4YFsL8M0PMXcvk=; b=fW/gHi2SFd8hCsDFtvWffuie+SAtL2nGCCfLXbTCEnbrYitJV6yzLUJ9aIo95s71qQ L3u5KBmvEWxclTZGxnNtl40kfAccBF8Shz+PSowJoo9EAjPJ6v9wZa1ornY/zwbNJQU2 K1xkCXEqtSbvLr/3JvtTakaU+QVAyO9W1zAbWaCFYsLZ2VKZ38TazR9abG6HrA5gXfdO nCnun42jnXLUlBxiIS8+wsRomIOEGiWadrMT5XDNTE7H+ahslDvnxTuhdSgxW55jAZ8c yEI6OKEzJPqEY/pqkc+XTUxQ0XbXdKH4MfDQO2melPqXFZgGjYFG7siuhSVCNmbs6SOM /Adw== 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=kAjJkCSR5rLgc1ik/eORDjpCuJ13N4YFsL8M0PMXcvk=; b=sqWRANRg5B4zPQq3anhxTudqzpGtzRj6cNqWCKrjeh+VUB92X5YSbkqpaQZ9dISDu9 t41MJkmRxqWNequbg8+qjEKd4giXjIMhVze0sW0n8fSpX3xUu4VPZYY1EL6Z65fdXpMC yBI475tGnhjA70IEa45D77aMfgs4m1LZNyIEQgLLMywt0kg7Cce/JttzeWWtozjq01ge 9zzAk9EtB7U1QPVElIfowt5wMGlkq5T7cgQvyly+u2tCQ3NUq5Rpa2dh7iWdB7nurTXy U0iCZKW586qd0ulZ7dGA9G56y9P0gL8WDBe7BP8Y2P5UDlFFD0DrcFBkrB+FT5g8gi9h x+OQ== X-Gm-Message-State: AOAM533NtLt5IqbrGNXxrnGVCQ4mP320ZyUukuDejfYg04ULuzEGsplv C5dE7BZY2KP0gP5X1tB2QLs= X-Google-Smtp-Source: ABdhPJy7KB/BCYQka2iGO7TjJXlCZ/I+KAjMa1h8DqnkrCO/4hsneoPd887PBhZKze0g3uqRqZqnOQ== X-Received: by 2002:a63:8c59:: with SMTP id q25mr7556125pgn.292.1635150834030; Mon, 25 Oct 2021 01:33:54 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:33:53 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 05/12] elfcore: make prpsinfo always get a nul terminated task comm Date: Mon, 25 Oct 2021 08:33:08 +0000 Message-Id: <20211025083315.4752-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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. Replacing strncpy() with strscpy_pad() can avoid this warning. This patch also replace the hard-coded 16 with TASK_COMM_LEN to make it more compatible with task comm size change. I also verfied if it still work well when I extend the comm size to 24. struct elf_prpsinfo is used to dump the task information in userspace coredump or kernel vmcore. Below is the verfication of vmcore, crash> ps PID PPID CPU TASK ST %MEM VSZ RSS COMM 0 0 0 ffffffff9d21a940 RU 0.0 0 0 [swapper/0] > 0 0 1 ffffa09e40f85e80 RU 0.0 0 0 [swapper/1] > 0 0 2 ffffa09e40f81f80 RU 0.0 0 0 [swapper/2] > 0 0 3 ffffa09e40f83f00 RU 0.0 0 0 [swapper/3] > 0 0 4 ffffa09e40f80000 RU 0.0 0 0 [swapper/4] > 0 0 5 ffffa09e40f89f80 RU 0.0 0 0 [swapper/5] 0 0 6 ffffa09e40f8bf00 RU 0.0 0 0 [swapper/6] > 0 0 7 ffffa09e40f88000 RU 0.0 0 0 [swapper/7] > 0 0 8 ffffa09e40f8de80 RU 0.0 0 0 [swapper/8] > 0 0 9 ffffa09e40f95e80 RU 0.0 0 0 [swapper/9] > 0 0 10 ffffa09e40f91f80 RU 0.0 0 0 [swapper/10] > 0 0 11 ffffa09e40f93f00 RU 0.0 0 0 [swapper/11] > 0 0 12 ffffa09e40f90000 RU 0.0 0 0 [swapper/12] > 0 0 13 ffffa09e40f9bf00 RU 0.0 0 0 [swapper/13] > 0 0 14 ffffa09e40f98000 RU 0.0 0 0 [swapper/14] > 0 0 15 ffffa09e40f9de80 RU 0.0 0 0 [swapper/15] It works well as expected. Reported-by: kernel test robot Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- fs/binfmt_elf.c | 2 +- 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..afa0eb45196b 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]; char pr_psargs[ELF_PRARGSZ]; }; diff --git a/include/linux/elfcore.h b/include/linux/elfcore.h index 2aaa15779d50..8d79cd58b09a 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]; /* 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 Mon Oct 25 08:33: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: 12581065 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 D0D6BC433EF for ; Mon, 25 Oct 2021 08:34:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDDC460F46 for ; Mon, 25 Oct 2021 08:34:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232385AbhJYIgh (ORCPT ); Mon, 25 Oct 2021 04:36:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232252AbhJYIgU (ORCPT ); Mon, 25 Oct 2021 04:36:20 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02C21C06122A; Mon, 25 Oct 2021 01:33:57 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id c4so10185932pgv.11; Mon, 25 Oct 2021 01:33:56 -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=0MARTQhRayCcJOXrt50qrZSWHcrTOqEBviMLv+qW86Q=; b=XP9d6g5akaizE8xXosLToU+YDFW2+ji6UQwvG9rY0KePWcCtYWku40Pftn6MNFy6ip vn2fAFRhM2XEAKVYSUOXMorB9/KfaXT5tIoXXEQO4+QGgcoJMtoUh1GL6ACnYpUx6+3C QWv23PsERcEm/e+kNkJeknBljJ82nng5FtIei5wWu5KnnZsjLSmcD0c/G7mOTvMYxc7r FDpVDKE+aQraRJ2VZ/WII3FFKGCj75F4Se9RsMn23gkqa7b8qz8f+bE8VohWIdLZDA8L r77tFIHw52606BnHROajGx+deZ42CI20qBGSU6LCXqjGc1MuIlzzx5bY9H37DUsYIIvm cgIQ== 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=0MARTQhRayCcJOXrt50qrZSWHcrTOqEBviMLv+qW86Q=; b=egbhd1kOY6kAuHk547oF/0Cp6FXgoF3hKOXX5yC/js2+tGZMYcem87931LOgj+5lYZ DfX99U64HXZMg0s0jIcV4HucBkvUedOIRAqDjWDMJ6v8jd37GMFZC0chGPRxW1qsHuS0 2+KwBH2ku5trnD2ep2ezodCclR1rTjTKfh3KOFE+/uT8ynsMsx304Wgh9YD4YMmCk1dq jO7SG/Lx/XHRMumKTFpbbx8utIKtpK4Xb9vo/W4LYg36LZAR/EIi2VJYtKh479yvMWUE pV1/R6HYrgoAMhxmvyKKBlvIqKy3iqrOQH+gqd58Jh03TyhAZ9OB8bg5WdFkboyG9qKm 8cbw== X-Gm-Message-State: AOAM530NYLosPv2jzL/oWrNWnDNX/usWJOp+ydmI5pf+hCriyyxcSlAd Hi2yqVNsoKO7XAcrF/ltf7Q= X-Google-Smtp-Source: ABdhPJw+MS/fFYKdGRF6+qFNhT0P9QZUUEFfE9dLlDbmgJIuvaqC53bEnXgTwCqGCnrhahx5AU6oUw== X-Received: by 2002:a63:7504:: with SMTP id q4mr12363197pgc.103.1635150836561; Mon, 25 Oct 2021 01:33:56 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:33:56 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 06/12] samples/bpf/test_overhead_kprobe_kern: make it adopt to task comm size change Date: Mon, 25 Oct 2021 08:33:09 +0000 Message-Id: <20211025083315.4752-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org bpf_probe_read_kernel_str() will add a nul terminator to the dst, then we don't care about if the dst size is big enough. This patch also replaces the hard-coded 16 with TASK_COMM_LEN to make it adopt to task comm size change. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek Reviewed-by: Kees Cook --- samples/bpf/test_overhead_kprobe_kern.c | 11 ++++++----- samples/bpf/test_overhead_tp_kern.c | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/samples/bpf/test_overhead_kprobe_kern.c b/samples/bpf/test_overhead_kprobe_kern.c index f6d593e47037..8fdd2c9c56b2 100644 --- a/samples/bpf/test_overhead_kprobe_kern.c +++ b/samples/bpf/test_overhead_kprobe_kern.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -22,17 +23,17 @@ int prog(struct pt_regs *ctx) { struct signal_struct *signal; struct task_struct *tsk; - char oldcomm[16] = {}; - char newcomm[16] = {}; + char oldcomm[TASK_COMM_LEN] = {}; + char newcomm[TASK_COMM_LEN] = {}; u16 oom_score_adj; u32 pid; tsk = (void *)PT_REGS_PARM1(ctx); pid = _(tsk->pid); - bpf_probe_read_kernel(oldcomm, sizeof(oldcomm), &tsk->comm); - bpf_probe_read_kernel(newcomm, sizeof(newcomm), - (void *)PT_REGS_PARM2(ctx)); + bpf_probe_read_kernel_str(oldcomm, sizeof(oldcomm), &tsk->comm); + bpf_probe_read_kernel_str(newcomm, sizeof(newcomm), + (void *)PT_REGS_PARM2(ctx)); signal = _(tsk->signal); oom_score_adj = _(signal->oom_score_adj); return 0; diff --git a/samples/bpf/test_overhead_tp_kern.c b/samples/bpf/test_overhead_tp_kern.c index eaa32693f8fc..80edadacb692 100644 --- a/samples/bpf/test_overhead_tp_kern.c +++ b/samples/bpf/test_overhead_tp_kern.c @@ -4,6 +4,7 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ +#include #include #include @@ -11,8 +12,8 @@ struct task_rename { __u64 pad; __u32 pid; - char oldcomm[16]; - char newcomm[16]; + char oldcomm[TASK_COMM_LEN]; + char newcomm[TASK_COMM_LEN]; __u16 oom_score_adj; }; SEC("tracepoint/task/task_rename") From patchwork Mon Oct 25 08:33: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: 12581067 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 2E783C4332F for ; Mon, 25 Oct 2021 08:34:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1BF0960F46 for ; Mon, 25 Oct 2021 08:34:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232414AbhJYIgu (ORCPT ); Mon, 25 Oct 2021 04:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232202AbhJYIgZ (ORCPT ); Mon, 25 Oct 2021 04:36:25 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39EADC061224; Mon, 25 Oct 2021 01:33:59 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id v16so2028429ple.9; Mon, 25 Oct 2021 01:33:59 -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=3JLxwHM1CeX0o7W4dwtTtvlyCiBChK2EpomgZ3q4G2c=; b=ePdfPG1JTA0ck7rtQ5KzZPGFF1sIvEFh4aTe6YJByMYFNpp44OqKvD13fZGA4EZ6id sDRU5XC4NgVOeJORW05ElLhXB73fHs4A5lqGI0Z7JMTeW75f56tnj84uRuv3fDoflktv Cxg3lG9LcxZLJ/4VJNZ0fVFD5yyADpYIxDzDVsDash7oLO/wcCtNZIq1FojiTpZferwd VHIPB117F8ZtuVZzPOovDkUTmtxWku9LUmVUih/uPrbAQChABOXO7CsMVqYc1mzESNGe zSwNavI52UykTZZUy3W4/sXxoXKFZCj+GJQh30XLp2LOZEDtBO8nscEpn1CCcw2KKcxa h5gQ== 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=3JLxwHM1CeX0o7W4dwtTtvlyCiBChK2EpomgZ3q4G2c=; b=PhdPLVRhMtAZq6yQY9LzwTbg02JzH4QRbv3bXP3Sw7A0r2td0q9XUGK9d28DR6n7Nr PETYKMiOjPBvvJr+TwfRZ+92/WD8gQycLCfM0gWbSaIWxTDp9biS91iN+wHbx0wrBSie Sgb6H6DRX9RjkHE7alnVfH1SIn8VvRHdQ5UZ8deWPoMzxlUXkj7wqKgJ1H8Cr5M2LJFP UyLkJGkNiPwB5D49/KAz/JzrZv0YG0fXI85Zgtuw0UafRMfgSVcCpowBcIa46KtM4MLB T0B1CRxZitPvL0Hd0Q1tqjt7MXYT0aoawYHeskJ8Rxb/iY5N6yNNNJmHhAupgLqsZym8 u/6w== X-Gm-Message-State: AOAM5313O/LQd9bYKsrF5yL6aw8kvFKkgE/fzto1SpEVFbJMqkn/4skL zZc/IxU6G1THoUU3yBgeqV8= X-Google-Smtp-Source: ABdhPJzKtmTPywPSXUOghfkjQUrKogUwRUlblGA2CFK9iX/Cg60lUvJHKUYmf90ZIfyJxDns3bO2sg== X-Received: by 2002:a17:903:32c7:b0:13e:ea76:f8cb with SMTP id i7-20020a17090332c700b0013eea76f8cbmr15237119plr.74.1635150838815; Mon, 25 Oct 2021 01:33:58 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:33:58 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 07/12] samples/bpf/offwaketime_kern: make sched_switch tracepoint args adopt to comm size change Date: Mon, 25 Oct 2021 08:33:10 +0000 Message-Id: <20211025083315.4752-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The sched:sched_switch tracepoint is derived from kernel, we should make its args compitable with the kernel. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- samples/bpf/offwaketime_kern.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime_kern.c index 4866afd054da..eb4d94742e6b 100644 --- a/samples/bpf/offwaketime_kern.c +++ b/samples/bpf/offwaketime_kern.c @@ -113,11 +113,11 @@ static inline int update_counts(void *ctx, u32 pid, u64 delta) /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ struct sched_switch_args { unsigned long long pad; - char prev_comm[16]; + char prev_comm[TASK_COMM_LEN]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN]; int next_pid; int next_prio; }; From patchwork Mon Oct 25 08:33: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: 12581069 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 6654DC43217 for ; Mon, 25 Oct 2021 08:34:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51C53610C7 for ; Mon, 25 Oct 2021 08:34:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbhJYIgz (ORCPT ); Mon, 25 Oct 2021 04:36:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232480AbhJYIg2 (ORCPT ); Mon, 25 Oct 2021 04:36:28 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 762DEC061231; Mon, 25 Oct 2021 01:34:01 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id c4so3517461plg.13; Mon, 25 Oct 2021 01:34:01 -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=TS8muz6Ak9DGU3l2L96V+UecMUYveGNsphx64n4dYOI=; b=M2FolzUKrmB9JdFI0MSqy5ChbO8Ja0Pf8UZPZm02u3xFvWDKNyZXc8Dym/hG4NIPAA 4ZpmbwlCuUUeXOEUxchfZH8bRN3iDp6AZUQKd3pXsduzQL8O8nHlQvwfOCN9Flkn1GOl pO4FWJRCWhgdfn+6H0Tj7wfb65dY0IkXl43ypxIQ43r8iOzN5hV9R26R/C7mw0Ba27Os 1WBeZUEUhqNN7swBZp+UXeUn5C/uwh77MU4Emv2Kdba0wtcmAGlRQyFdsd6oKxWfAMOS VWr/1XcWd7zxnJOv7N2ncV8aa37dmE9NYCGJXPzYZC+zOL+03zINlyNRqsvOAw4gqU2o V0Ig== 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=TS8muz6Ak9DGU3l2L96V+UecMUYveGNsphx64n4dYOI=; b=DGZNIDl+VksXdb0i38MIyjUU1AJwKD8WzuaRgQV/cpBPEisXIYce6Xq7LUKeMiy6pY NfYVwYEq+J0PfKVnbNzkLX6I6eMGcEGi7Bzh/DXn8bjaaEqqOTmhyw0AmQu/pnh1z9u7 gfJRPR7fxFKFREiHHAfMOvFE/aEsvQhkCk9KYUN1Shci3imQy1yR41MdifvSI1sYBBGO zBuZfCzKjs9uvujW2wQdlhjNKtILBJX4w53LKxf9OVHWzCfn0v5qU7gtQmuDmE7AbQXn fg3bOtFOkhu7f5bSuAJSv6uCOtTmAT04tZxg6+O0nqPF/52hHOi7FoTfOwy59mZQUTfl P0ug== X-Gm-Message-State: AOAM531REW7s0EDkk/GrhP67vEoVVCWDvy1CcoFlTv38IKnmtRNfbO74 T8YA1qnnUWU+9UxsiVgTkW8= X-Google-Smtp-Source: ABdhPJwksxFE2tQQyrV3PnanxuzSjX04lpr4xzNjspd8MjAGIknTaDm6AMAf9hKdRj7ef0WBXIAmdQ== X-Received: by 2002:a17:90b:4c88:: with SMTP id my8mr18897686pjb.49.1635150841055; Mon, 25 Oct 2021 01:34:01 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:34:00 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 08/12] tools/bpf/bpftool/skeleton: make it adopt to task comm size change Date: Mon, 25 Oct 2021 08:33:11 +0000 Message-Id: <20211025083315.4752-9-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org bpf_probe_read_kernel_str() will add a nul terminator to the dst, then we don't care about if the dst size is big enough. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c index d9b420972934..f70702fcb224 100644 --- a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c +++ b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c @@ -71,8 +71,8 @@ int iter(struct bpf_iter__task_file *ctx) e.pid = task->tgid; e.id = get_obj_id(file->private_data, obj_type); - bpf_probe_read_kernel(&e.comm, sizeof(e.comm), - task->group_leader->comm); + bpf_probe_read_kernel_str(&e.comm, sizeof(e.comm), + task->group_leader->comm); bpf_seq_write(ctx->meta->seq, &e, sizeof(e)); return 0; From patchwork Mon Oct 25 08:33: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: 12581071 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 6BCE5C433FE for ; Mon, 25 Oct 2021 08:34:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55B4D604AC for ; Mon, 25 Oct 2021 08:34:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232632AbhJYIg5 (ORCPT ); Mon, 25 Oct 2021 04:36:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232319AbhJYIg3 (ORCPT ); Mon, 25 Oct 2021 04:36:29 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD3FDC061243; Mon, 25 Oct 2021 01:34:03 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id n11-20020a17090a2bcb00b001a1e7a0a6a6so7120583pje.0; Mon, 25 Oct 2021 01:34:03 -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=1md3Mevkn+CBLiLByux/J8bl1HeiftdQPKT0KXDTr4s=; b=ippqS7oyy/Xxu6ZxvpuafUWSvpsfvfwE/3J3JNAouce3xXBt5wOOlT/RiZpgQ0gzj8 PKadBOKIY75j0iZuHaUbBgBpNPw5ZbxNYHrf5n2Tsn9IYbPusgJzNUZTTGkGSwjkBp6n oK9EKcykGE6fGX+zqXz9NTA+gFaqMFBkTthGhqY2C0RpW4E8fnrfZGLFHgh2pQRJewxw 2FLLyudFZ5ofXs9aNR1UXn5m5pgHHAflMUH3uYxlOfVxySeAykoWnZCRjhUNXEj0A8Ce 2/4PFZ/n097pvj+lPKb+n1HLjmSbAFa4LCwkEIn8vMqH689VQmoKK20lbaOX2cjARGm2 i99w== 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=1md3Mevkn+CBLiLByux/J8bl1HeiftdQPKT0KXDTr4s=; b=GNQRk2cMCWKQDrr5BC9yvnVQHl1yP/tnlyu9Cv0F50X86gZx1AZQ96cf/3hb44Oa1k 9ZhMkT98pjyR101E7NtOyFJcBmxkShg3CBvTOf08mxsnaY2tDrWB41B8M2T1TqeKOcwL Zgz2uOdgNsBqBkXu/oIpddsJNwtQd5EG+OUA/63hLEz4aTBKKuzAL9xaClHsTrKfbldO sN5aM0T4TrEA/mie59OuPQGNJ6r2ge+rr7shr+P+BjI/y1vvCWfpzzuuB1NYF+gt/18W KpWMBi6HJVK3DVRPipQtFqs42vQVM6QRMqTzzdjZJrSZvRpPP9NNalmc4iUmtq/vr/FO 10JQ== X-Gm-Message-State: AOAM5312YHGJyHD2/p3gJzw9rxy1j8loEyezCwW3B4yXpJmMs8jUVkh8 JTmlGehexbPXoOt9AuMLMoc= X-Google-Smtp-Source: ABdhPJwx3ky7vXb/J2lUahfhiiyc2nfJn2hGx6yFG/luHydF3goGPz/vPzvSnaj5EdOe4N7u8ko/aQ== X-Received: by 2002:a17:90a:284c:: with SMTP id p12mr12363516pjf.95.1635150843340; Mon, 25 Oct 2021 01:34:03 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:34:02 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 09/12] tools/perf/test: make perf test adopt to task comm size change Date: Mon, 25 Oct 2021 08:33:12 +0000 Message-Id: <20211025083315.4752-10-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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. Replace old hard-coded 16 with the new one can fix the warning, but we'd better make the test accept both old and new sizes, then it can be backward compatibility. After this patch, the perf-test succeeds no matter task comm is 16 or 24 - 15: Parse sched tracepoints fields : Ok This patch is a preparation for the followup patch. Reported-by: kernel test robot Suggested-by: Arnaldo Carvalho de Melo Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- tools/include/linux/sched.h | 11 +++++++++++ tools/perf/tests/evsel-tp-sched.c | 26 ++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 tools/include/linux/sched.h diff --git a/tools/include/linux/sched.h b/tools/include/linux/sched.h new file mode 100644 index 000000000000..0d575afd7f43 --- /dev/null +++ b/tools/include/linux/sched.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_SCHED_H +#define _TOOLS_LINUX_SCHED_H + +/* Keep both length for backward compatibility */ +enum { + TASK_COMM_LEN_16 = 16, + TASK_COMM_LEN = 24, +}; + +#endif /* _TOOLS_LINUX_SCHED_H */ diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c index f9e34bd26cf3..029f2a8c8e51 100644 --- a/tools/perf/tests/evsel-tp-sched.c +++ b/tools/perf/tests/evsel-tp-sched.c @@ -1,11 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include "evsel.h" #include "tests.h" #include "debug.h" -static int evsel__test_field(struct evsel *evsel, const char *name, int size, bool should_be_signed) +static int evsel__test_field_alt(struct evsel *evsel, const char *name, + int size, int alternate_size, bool should_be_signed) { struct tep_format_field *field = evsel__field(evsel, name); int is_signed; @@ -23,15 +25,24 @@ static int evsel__test_field(struct evsel *evsel, const char *name, int size, bo ret = -1; } - if (field->size != size) { - pr_debug("%s: \"%s\" size (%d) should be %d!\n", + if (field->size != size && field->size != alternate_size) { + pr_debug("%s: \"%s\" size (%d) should be %d", evsel->name, name, field->size, size); + if (alternate_size > 0) + pr_debug(" or %d", alternate_size); + pr_debug("!\n"); ret = -1; } return ret; } +static int evsel__test_field(struct evsel *evsel, const char *name, + int size, bool should_be_signed) +{ + return evsel__test_field_alt(evsel, name, size, -1, should_be_signed); +} + int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtest __maybe_unused) { struct evsel *evsel = evsel__newtp("sched", "sched_switch"); @@ -42,7 +53,8 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes return -1; } - if (evsel__test_field(evsel, "prev_comm", 16, false)) + if (evsel__test_field_alt(evsel, "prev_comm", TASK_COMM_LEN_16, + TASK_COMM_LEN, false)) ret = -1; if (evsel__test_field(evsel, "prev_pid", 4, true)) @@ -54,7 +66,8 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes if (evsel__test_field(evsel, "prev_state", sizeof(long), true)) ret = -1; - if (evsel__test_field(evsel, "next_comm", 16, false)) + if (evsel__test_field_alt(evsel, "next_comm", TASK_COMM_LEN_16, + TASK_COMM_LEN, false)) ret = -1; if (evsel__test_field(evsel, "next_pid", 4, true)) @@ -72,7 +85,8 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes return -1; } - if (evsel__test_field(evsel, "comm", 16, false)) + if (evsel__test_field_alt(evsel, "comm", TASK_COMM_LEN_16, + TASK_COMM_LEN, false)) ret = -1; if (evsel__test_field(evsel, "pid", 4, true)) From patchwork Mon Oct 25 08:33: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: 12581073 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 93F34C433F5 for ; Mon, 25 Oct 2021 08:34:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E7436108B for ; Mon, 25 Oct 2021 08:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232546AbhJYIhO (ORCPT ); Mon, 25 Oct 2021 04:37:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbhJYIgc (ORCPT ); Mon, 25 Oct 2021 04:36:32 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19D38C06118D; Mon, 25 Oct 2021 01:34:06 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id gn3so7715906pjb.0; Mon, 25 Oct 2021 01:34:06 -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=FimO42wHtyfBgzya/uAaxmcTkfbAGy9rm+wuLjXRCpM=; b=CMzBBLZvEjXS7erkK4gC8zgIdfsYiNz7dGUg+d49ScAYY+q/TShlcX2Ju9kusSxdEb a01pYcPiTgrVOP16z1WWCDbus2MLMoqyEtRZsKF/7I+556oB8thmUiWvwLCCpaKcQafk Q90z1GqDhsyVHwTvOPZwkwT2UGNiLDen6CuNr1/umo5xRLQ0dY8i6HLK+wtn+TAosQfr Gx9CNRh8KkLCvQ8YsPpvVqpNHjwYP40LzSyOVqHsNeZe1Gq2hOhsXNidrxl2ApprLLfy +sgZXnWrt+SqR2w8WyrxCCvutwz8aEMBZtUCHn0oVbuzBtSXFuPLQphqjh15nH9ExfPA M8FQ== 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=FimO42wHtyfBgzya/uAaxmcTkfbAGy9rm+wuLjXRCpM=; b=LHzJCXNPTUUn9d2DPLnw+oNJ6bBmtMCpkxp1Bo83EDtimHesMe7zOVpgeC3XIFUgaH icqDuVN0odDyF5BJxnc/7cCxODyh9HlTAGZQhunnu23akoLUYPpNEDA1T6850BC3ooH1 1TcFKP8Cc0c1wtJLLBQr4LFL7m10NOCUcchJHzjUMdOnebZLuU8jegqcPVLwZ2IG5+La qUk1qZbm6WQabvUYfLy2dfgWJr1AoAhSAwy6eBNCeLqUfHrdNUw226r7Vid1FDz95z9U /Sy4M8GSxF5ZMnvT6nfh7dWcJAggLsTgNWQfRXnk/vdQGuBrxgAOy1/I5wbgj91JDxrd Y7aA== X-Gm-Message-State: AOAM532/+4JV/EFegz+6JRrLrQoBGoOfqalcBogiKqLrL5q28UI5eh/Y dl/tjM/nV6aNWsxOLXo3IYQ= X-Google-Smtp-Source: ABdhPJz2AlsUyCzUZMxKu+M0vjHOcLRcbjq0i+wwmiMJBlPaI9iPLMs9CncCZefQOcgo7EXDtDLr1Q== X-Received: by 2002:a17:90a:62c9:: with SMTP id k9mr21015248pjs.52.1635150845679; Mon, 25 Oct 2021 01:34:05 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:34:05 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 10/12] tools/testing/selftests/bpf: make it adopt to task comm size change Date: Mon, 25 Oct 2021 08:33:13 +0000 Message-Id: <20211025083315.4752-11-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The hard-coded 16 is used in various bpf progs. These progs get task comm either via bpf_get_current_comm() or prctl() or bpf_core_read_str(), all of which can work well even if the task comm size is changed. In these BPF programs, one thing to be improved is the sched:sched_switch tracepoint args. As the tracepoint args are derived from the kernel, we'd better make it same with the kernel. So the macro TASK_COMM_LEN is converted to type enum, then all the BPF programs can get it through BTF. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- include/linux/sched.h | 9 +++++++-- tools/testing/selftests/bpf/progs/test_stacktrace_map.c | 6 +++--- tools/testing/selftests/bpf/progs/test_tracepoint.c | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index c1a927ddec64..124538db792c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -274,8 +274,13 @@ struct task_group; #define get_current_state() READ_ONCE(current->__state) -/* Task command name length: */ -#define TASK_COMM_LEN 16 +/* + * Define the task command name length as enum, then it can be visible to + * BPF programs. + */ +enum { + TASK_COMM_LEN = 16, +}; extern void scheduler_tick(void); diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c index 00ed48672620..e9b602a6dc1b 100644 --- a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c +++ b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2018 Facebook -#include +#include #include #ifndef PERF_MAX_STACK_DEPTH @@ -41,11 +41,11 @@ struct { /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ struct sched_switch_args { unsigned long long pad; - char prev_comm[16]; + char prev_comm[TASK_COMM_LEN]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN]; int next_pid; int next_prio; }; diff --git a/tools/testing/selftests/bpf/progs/test_tracepoint.c b/tools/testing/selftests/bpf/progs/test_tracepoint.c index 4b825ee122cf..f21982681e28 100644 --- a/tools/testing/selftests/bpf/progs/test_tracepoint.c +++ b/tools/testing/selftests/bpf/progs/test_tracepoint.c @@ -1,17 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2017 Facebook -#include +#include #include /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ struct sched_switch_args { unsigned long long pad; - char prev_comm[16]; + char prev_comm[TASK_COMM_LEN]; int prev_pid; int prev_prio; long long prev_state; - char next_comm[16]; + char next_comm[TASK_COMM_LEN]; int next_pid; int next_prio; }; From patchwork Mon Oct 25 08:33: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: 12581075 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 5BC88C433EF for ; Mon, 25 Oct 2021 08:35:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48CB561029 for ; Mon, 25 Oct 2021 08:35:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232702AbhJYIhf (ORCPT ); Mon, 25 Oct 2021 04:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbhJYIgn (ORCPT ); Mon, 25 Oct 2021 04:36:43 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CCDAC061764; Mon, 25 Oct 2021 01:34:08 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id t11so7395236plq.11; Mon, 25 Oct 2021 01:34:08 -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=w7dW1iNbq1Wg2WuKYJlcYSndnkowZDcd1bFguHKF6IE=; b=U4i0No+EGDrlJQePYnoMIOFXR8R7nulw7jyU+4G06XBewuwtvRrbzHuzPd0qpgHOFA pcSNEIYL3ncWLV8C32z/LvGr7OsnV7o61Qie1FqPfkGj7vpzYELToUSZmNo8Ip3dZUhz BuCnVkXiLGcsBJG19c95EuFLLvDshR/dOYVCczQwJYqtgiKMU5TCBGR2iKr/JtqfF1vT N91zQnWaAmVc1UkEqkyAkH4BeiRGW/2Z9EzoW1rr9B6FWkZMUznOG6iyw/6c14qRkPRl kDbqpSwf19sWPYlrUhhTt1F1eI4WPYl7Yt7KKN1smPCDtwaZ03fW7SO6+/A/myUKSpDh mMVg== 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=w7dW1iNbq1Wg2WuKYJlcYSndnkowZDcd1bFguHKF6IE=; b=MOQ9s1WrBJhhX6OVSS3MOLQ/1wjPB18rAfdHeFVZz6ktA5PMz7EiLSSBOKjmY4eeaI 6BqqVLVKT6dx1cGPZZ+9Vgx1r9x6tJ3mdBMhk97vrk4Uz40DJlQszYwYoW3DLkHawHVe AXiSRKYmJT3yWq9TseBqMv2UdE08kZ8m+ybLMBBI0NtB91KqrEzMOpM1HKbs5YVR036r SM6Q21QN7VArP4zGP83AjWt3KN1+MHUpWaXSNiV5n+pSIjt3L8RzRu4F+8Suo16tRkK0 cz/yxne34ZuAt/uMOdxmM3uHL9bqIVoDHhOK4cqPQZiTJJjPGaOBYC+oLViNN8KxDq20 kOuQ== X-Gm-Message-State: AOAM5328bG048KxIxZWmmyqPKSYfryI9WraC1E86g1fqJ2ddLL4hWMtf y4gp1USvtOHjHQUoUxOroh0= X-Google-Smtp-Source: ABdhPJwFC4zTTp4l0K+QrkkRFDcEYhrKjwwpL/YCU9oKIw4H/35xwZzLIb7TJAj/167JmR/qYIhF5g== X-Received: by 2002:a17:90a:4890:: with SMTP id b16mr19994866pjh.82.1635150847878; Mon, 25 Oct 2021 01:34:07 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:34:07 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 11/12] sched.h: extend task comm from 16 to 24 Date: Mon, 25 Oct 2021 08:33:14 +0000 Message-Id: <20211025083315.4752-12-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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 by extending comm size to 24 bytes. task_struct is growing rather regularly by 8 bytes. After this change, the truncated kthreads listed above will be displayed as: rcu_tasks_kthread rcu_tasks_rude_kthread rcu_tasks_trace_kthread poll_mpt3sas0_statu ext4-rsv-conversion xfs-reclaim/sdf1 xfs-blockgc/sdf1 xfs-inodegc/sdf1 audit_send_reply ecryptfs-kthread vfio-irqfd-cleanup jbd2/nvme0n1p2-8 As we have converted all the unsafe copy of task comm to the safe one, this change won't make any trouble to the kernel or the in-tree tools. The safe one and unsafe one of comm copy as follows, Unsafe Safe strlcpy strscpy_pad strncpy strscpy_pad bpf_probe_read_kernel bpf_probe_read_kernel_str bpf_core_read_str bpf_get_current_comm perf_event__prepare_comm prctl(2) Regarding the possible risk it may take to the out-of-tree user tools, if the user tools get the task comm through kernel API like prctl(2), bpf_get_current_comm() and etc, the tools still work well after this change. While If the user tools get the task comm through direct string copy, it must make sure the copied string should be with a nul terminator. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- include/linux/sched.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 124538db792c..490d12eabe44 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -279,7 +279,7 @@ struct task_group; * BPF programs. */ enum { - TASK_COMM_LEN = 16, + TASK_COMM_LEN = 24, }; extern void scheduler_tick(void); From patchwork Mon Oct 25 08:33: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: 12581077 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 5DD69C4332F for ; Mon, 25 Oct 2021 08:35:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47D4661078 for ; Mon, 25 Oct 2021 08:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232473AbhJYIhq (ORCPT ); Mon, 25 Oct 2021 04:37:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232460AbhJYIgu (ORCPT ); Mon, 25 Oct 2021 04:36:50 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CD5CC079783; Mon, 25 Oct 2021 01:34:10 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id t5-20020a17090a4e4500b001a0a284fcc2so10840189pjl.2; Mon, 25 Oct 2021 01:34: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=3b5F5wGACMd69eL0I262MHV9xwxefmfYtcns+//hWu4=; b=EJ9gWHO/qDcGuCu2SsMmuJNFlQLwRCArk3fC9JGAfPmJ1R7j5Doski35qo1J9+YIyB xm9NVqk3GU9iu5jlaYJd0V9e7a6g2K/LS84Mg+54kw+yNvxF/aPBJ/k8tmCnuCjj8i1L LSU4qsZWYuEqhvhDGrqCW4TDzQIH1JQ58AeWQEgGKhJT8vza2qe/RJAzwOqkq11UUZjB PQz8nUzZNSW2Mr2C5W/gi2FvezUTcVW7PkRR84kUj4ri6G/5MYAdMVtDdLwezMSAw71C XedSRr/v//YmFqHoVS7TB3a0uqwPUD/gTPFY+yihxS6er+pf7khcm+JZC+5nn3DksKlg Fq9w== 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=3b5F5wGACMd69eL0I262MHV9xwxefmfYtcns+//hWu4=; b=e9gycdtl5okXe99qzeBWeKgGI/SQfabpIDyNn5lt9edDvFpxS1/UMAx7xaly99FT/j VuMGNi5rOALKZV14F5n//DKQ990r00liclX0nwl0SF9NHJNrD8eAioQTZy3wKcHcYvNE QoIJS9SOi00q7/G60MIIWwjEjasc82qSdcPEdD72bAGuVPu0jPKid5JntbVfD/ElxLaT UQIGk9auPfUodRQTOBCB2DNbGmPXiVndpATxhYNhZlRwgtLP9r9stgcbxEYl4ibyfaFP Voim6FWR5MKhrA+RasZ4iQBB9GOZiEUC0sBDKycW8kY72f8UDVCVsrIewi0aB9wiEPw2 YZNw== X-Gm-Message-State: AOAM533hqUsDypp1IetCPIWTVNqD67ZjTqgN9pfGj1c26m8WLOxb38qZ U24JLBg8YNb6sLHD8yWodUs= X-Google-Smtp-Source: ABdhPJyB546Sceoy6Mmun969JkLWcczoY+I0vjocLtE6F0/dLsge5k71yHQdO2hurNXalyhHA+nS/A== X-Received: by 2002:a17:90b:110d:: with SMTP id gi13mr19162609pjb.1.1635150850050; Mon, 25 Oct 2021 01:34:10 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:34:09 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 12/12] kernel/kthread: show a warning if kthread's comm is truncated Date: Mon, 25 Oct 2021 08:33:15 +0000 Message-Id: <20211025083315.4752-13-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- kernel/kthread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index 5b37a8567168..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.