Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp225054pxb; Wed, 20 Oct 2021 20:47:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyep8CXplqoQ3Cyuxrbl9SVkWrhfn+eHs7A1khicp9PiJVWHKHDn7ics3Gjme8FrwuDuooU X-Received: by 2002:a17:903:246:b0:13f:2ff9:8b93 with SMTP id j6-20020a170903024600b0013f2ff98b93mr2994473plh.54.1634788035286; Wed, 20 Oct 2021 20:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634788035; cv=none; d=google.com; s=arc-20160816; b=0oyqSnEPBuLTxErNdMheQh6/V/dS1xvm4nh6p2bK5JfniIhO5n8bH8lszEXpyjRBlO KRizHVBIrSVz9K/AHeYzPkgeP0BacNvMviZwAKMabp92/6KKbmlTT6wrNCchaPAkmwl+ oXNPg58ylrN1ZAb/oPosrXl87/4XKoST12ugZz81xoTS3U7Owj1V2BINO2+2oSGaQ78D QBZSrUdAr0yFOwVvePcpWvkGzseAPwSOYe4Ecb7kjrezkHjyqICgGPTKxd+y+0ZWaDNL il+lM6SsZJVdtBPrQzjWt9Fiulz+W0Bt4CuIEuJ8637cNwnG/6zXNn9xrFPtIovjKjPg rUVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pevXqfzk0a9mco3A0IBMgl8TtIgUhm0DLJ2rQWdresY=; b=geJvOi4A9z0+5q9aO0MwohKqYbQhJqnR1/Rybb1JI2oYGbxKO0OSBRKzTMqPzcphDW FiG7iySB8d/R4cPZtXO7ZBJLnLz4bkQPEWbbOrfNs6zl8ZIA6dWeTJmlshRsrBI5QkmL arR43AFBQWNeOdQFczhuY30qJctJ9P7uOCrUZGgQg5bH8PdfaKJMxpBuf7VFOH6QN8sr RqMx9yJ4YRD6l5dFaOgCJZoxomVw901dJrGgPXqglrLIc4oWn/YDwylZ1m3lk0spoKLa H4BePeQN2YLxABwOa6OAKgAO2LyBeLNuDIRNucYAK1ZaQUBu9m6wRNG25T/33cD1cMyW nESw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IVwXWPNp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si6424117pfc.291.2021.10.20.20.47.02; Wed, 20 Oct 2021 20:47:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IVwXWPNp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231607AbhJUDsA (ORCPT + 99 others); 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-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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: 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 { -- 2.17.1