From patchwork Sat Aug 6 12:23:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 1664244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=INBvJ+bQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M0MJD3Cvpz9ryY for ; Sat, 6 Aug 2022 22:30:52 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4M0MJD23dyz3drc for ; Sat, 6 Aug 2022 22:30:52 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=INBvJ+bQ; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmx.de (client-ip=212.227.15.18; helo=mout.gmx.net; envelope-from=deller@gmx.de; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=INBvJ+bQ; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4M0MGj0Cljz2xr8 for ; Sat, 6 Aug 2022 22:29:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659788970; bh=EmdUhqjuBaZoiK7nIBlB85Ojty7fJP5lc36LTjVWwVI=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=INBvJ+bQUFTFz0lcSeGRgV6m1kaX6nAoKGYYByVdRDYxsSrpRe/+T3ysXO1Nlbb6T rbeMcROex7Mj11pA5nqtpIg9c1rukcUr6poZRBB9q9E/hPGcPKsjNZGfl3+685NPeG bUCkpzB0/gwFmxVIMZZSwh0n4EBrlgd/58JdC7O0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.170.46]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MFsZ3-1oCKlN2yp5-00HPpY; Sat, 06 Aug 2022 14:23:50 +0200 From: Helge Deller To: linux-s390@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, Josh Triplett , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 1/3] proc: Add get_task_cmdline_kernel() function Date: Sat, 6 Aug 2022 14:23:46 +0200 Message-Id: <20220806122348.82584-2-deller@gmx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220806122348.82584-1-deller@gmx.de> References: <20220806122348.82584-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:KkbEYe0kghWlFwQzjNuZb5/phQrAfDs2/UGiW7nK7hjXneYtmzA Tcmc4lEn26oFet83nGaNCsUOemp/lO74ocP4iy6dotsrngi6iHJIBhVQCe0Ex75F4MuvMIo 6wQo7U57hTdwN+EY+AMxpSbEsO2XQI+9BGBdiWoby5I3yP7hu0hEybBTdkkJqLNQ/RUI5B/ FAQ5+TXjSTjV/7By+RY8g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:A1Vk0kCc0cY=:+dTXNsvd9tEMjddN63Paq8 kZc0nP8/l/P2MLmTBttT3gWnrCc4De9JMhtbBwYN7VBeEmnv8hoEHUoQN/TWCSkS5TU7fk2Kz aHu0/S81PsGX5AyC9BWvJmYhXz2UJaAmFgPPSugoYYboVWW7miGgGplJq410bF6TSn+v6KzGV iW01uhX87nBhHCx//CCR+EU3txGfgJZOZZa7agZthJFG4TcWvG+ZiTxUENlVUlZl+HR94++3Z UYVhjtM62DgCGdt1Wms2X5GIFknj4YmQX/J5KzQUHPQgtOEdur2gV5W0mO+j6vGx+lruYYlLq V8qMYup0uvY7UKOzxCkpdnV3pjvrJi1BHV2APqkK78iDNr0khigfow8I8tN1G451CDRcZijBh u5IZNa/RbTLkVN0GsLDFz1uTj1ONSF43k+MkNLpl/W0u3o+0HLyylclHw0J0k/msGFaMFeYyN pl0expXDBROlSEF2dgSuNBoa//b0Ku/40EwHTj6kApJNRo40c82IgLtTuWU55aPBiEDvzA995 K0g6Ax2RMMRilF9ZjNVGB7lac4q8Ufg2J5gB3eSZWl8jf0hErSz4cyp1aK9kcPf712449H2i1 08BAdvNaVKW13YOkjLJLR8+tCR0ldhW50ad7phjqz02c0x99PegkmujpLpikHCBYwp4nroWdG RUiBUxCUucpu+WlQGdjv7mIo60AsTlQ48o/JeQ570COqJo/ZIWKyzqZvj/KVxDsg98G48ZUTn p7PnU2DYb8Ip0BWhrYHWDo3MFql7QcDMpz5GUZxHFR4ntg3Dy8Gk3UJHI2b8F2Jc42Rwi6oDA wbMzaErJ4Woxg3gjY8vr/rpIrYSQ2EHivHwzb8MNnsZc4EllFoKFDRY7J2+PmvgMqZ2Xt3yc8 r+DxWi0l7z9Hd+ImerzAU8LXzzePgm43SjXtSgj5rw8oV7AoV98MkVcaKizuAgokxjcN71vPU Bc0TFKo2xRexX9Do6+TYJ/+K7p3wz+mmRXB339e4tXrutBXMKA+cmReDtzi0O/jp7g3BD4MUI PdTBUaqTg3K8IMksyns+zthtoFTb4gvQmwSg04+2o9zy7wBU22SuR+p0HExX1MA5YPduyKe2n fKVbf3/sf05CN2bOV5dRAIEtMvj/VG2AJVr6szTx+OGWGd9I5NpY9/RsA== X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add a new function get_task_cmdline_kernel() which reads the command line of a process into a kernel buffer. This command line can then be dumped by arch code to give additional debug info via the parameters with which a faulting process was started. The new function re-uses the existing code which provides the cmdline for the procfs. For that the existing functions were modified so that the buffer page is allocated outside of get_mm_proctitle() and get_mm_cmdline() and instead provided as parameter. Signed-off-by: Helge Deller --- fs/proc/base.c | 68 +++++++++++++++++++++++++++-------------- include/linux/proc_fs.h | 5 +++ 2 files changed, 50 insertions(+), 23 deletions(-) -- 2.37.1 diff --git a/fs/proc/base.c b/fs/proc/base.c index 8dfa36a99c74..4da9a8b3c7d1 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -217,20 +217,17 @@ static int proc_root_link(struct dentry *dentry, struct path *path) */ static ssize_t get_mm_proctitle(struct mm_struct *mm, char __user *buf, size_t count, unsigned long pos, - unsigned long arg_start) + unsigned long arg_start, char *page) { - char *page; int ret, got; + size_t size; - if (pos >= PAGE_SIZE) + size = min_t(size_t, PAGE_SIZE, count); + if (pos >= size) return 0; - page = (char *)__get_free_page(GFP_KERNEL); - if (!page) - return -ENOMEM; - ret = 0; - got = access_remote_vm(mm, arg_start, page, PAGE_SIZE, FOLL_ANON); + got = access_remote_vm(mm, arg_start, page, size, FOLL_ANON); if (got > 0) { int len = strnlen(page, got); @@ -238,7 +235,9 @@ static ssize_t get_mm_proctitle(struct mm_struct *mm, char __user *buf, if (len < got) len++; - if (len > pos) { + if (!buf) + ret = len; + else if (len > pos) { len -= pos; if (len > count) len = count; @@ -248,16 +247,15 @@ static ssize_t get_mm_proctitle(struct mm_struct *mm, char __user *buf, ret = len; } } - free_page((unsigned long)page); return ret; } static ssize_t get_mm_cmdline(struct mm_struct *mm, char __user *buf, - size_t count, loff_t *ppos) + size_t count, loff_t *ppos, char *page) { unsigned long arg_start, arg_end, env_start, env_end; unsigned long pos, len; - char *page, c; + char c; /* Check if process spawned far enough to have cmdline. */ if (!mm->env_end) @@ -283,7 +281,7 @@ static ssize_t get_mm_cmdline(struct mm_struct *mm, char __user *buf, len = env_end - arg_start; /* We're not going to care if "*ppos" has high bits set */ - pos = *ppos; + pos = ppos ? *ppos : 0; if (pos >= len) return 0; if (count > len - pos) @@ -299,7 +297,7 @@ static ssize_t get_mm_cmdline(struct mm_struct *mm, char __user *buf, * pos is 0, and set a flag in the 'struct file'. */ if (access_remote_vm(mm, arg_end-1, &c, 1, FOLL_ANON) == 1 && c) - return get_mm_proctitle(mm, buf, count, pos, arg_start); + return get_mm_proctitle(mm, buf, count, pos, arg_start, page); /* * For the non-setproctitle() case we limit things strictly @@ -311,10 +309,6 @@ static ssize_t get_mm_cmdline(struct mm_struct *mm, char __user *buf, if (count > arg_end - pos) count = arg_end - pos; - page = (char *)__get_free_page(GFP_KERNEL); - if (!page) - return -ENOMEM; - len = 0; while (count) { int got; @@ -323,7 +317,8 @@ static ssize_t get_mm_cmdline(struct mm_struct *mm, char __user *buf, got = access_remote_vm(mm, pos, page, size, FOLL_ANON); if (got <= 0) break; - got -= copy_to_user(buf, page, got); + if (buf) + got -= copy_to_user(buf, page, got); if (unlikely(!got)) { if (!len) len = -EFAULT; @@ -335,12 +330,11 @@ static ssize_t get_mm_cmdline(struct mm_struct *mm, char __user *buf, count -= got; } - free_page((unsigned long)page); return len; } static ssize_t get_task_cmdline(struct task_struct *tsk, char __user *buf, - size_t count, loff_t *pos) + size_t count, loff_t *pos, char *page) { struct mm_struct *mm; ssize_t ret; @@ -349,23 +343,51 @@ static ssize_t get_task_cmdline(struct task_struct *tsk, char __user *buf, if (!mm) return 0; - ret = get_mm_cmdline(mm, buf, count, pos); + ret = get_mm_cmdline(mm, buf, count, pos, page); mmput(mm); return ret; } +/* + * Place up to maxcount chars of the command line of the process into the + * cmdline buffer. + */ +void get_task_cmdline_kernel(struct task_struct *tsk, + char *cmdline, size_t maxcount) +{ + int i; + + memset(cmdline, 0, maxcount); + get_task_cmdline(tsk, NULL, maxcount - 1, NULL, cmdline); + + /* remove NULs between parameters */ + for (i = 0; i < maxcount - 2; i++) { + if (cmdline[i]) + continue; + if (cmdline[i+1] == 0) + break; + cmdline[i] = ' '; + } +} + static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { struct task_struct *tsk; ssize_t ret; + char *page; BUG_ON(*pos < 0); tsk = get_proc_task(file_inode(file)); if (!tsk) return -ESRCH; - ret = get_task_cmdline(tsk, buf, count, pos); + page = (char *)__get_free_page(GFP_KERNEL); + if (page) { + ret = get_task_cmdline(tsk, buf, count, pos, page); + free_page((unsigned long)page); + } else + ret = -ENOMEM; put_task_struct(tsk); if (ret > 0) *pos += ret; diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index 81d6e4ec2294..9a256e86205c 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -158,6 +158,9 @@ int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task); #endif /* CONFIG_PROC_PID_ARCH_STATUS */ +void get_task_cmdline_kernel(struct task_struct *tsk, + char *cmdline, size_t maxcount); + #else /* CONFIG_PROC_FS */ static inline void proc_root_init(void) @@ -216,6 +219,8 @@ static inline struct pid *tgid_pidfd_to_pid(const struct file *file) return ERR_PTR(-EBADF); } +static inline void get_task_cmdline_kernel(struct task_struct *, char *, size_t) { } + #endif /* CONFIG_PROC_FS */ struct net; From patchwork Sat Aug 6 12:23:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 1664242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=apNzvozy; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M0MH45r0Yz9ryY for ; Sat, 6 Aug 2022 22:29:52 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4M0MGy1YJkz3bPP for ; Sat, 6 Aug 2022 22:29:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=apNzvozy; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmx.de (client-ip=212.227.15.19; helo=mout.gmx.net; envelope-from=deller@gmx.de; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=apNzvozy; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4M0MGh6xCMz2xGn for ; Sat, 6 Aug 2022 22:29:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659788969; bh=lELR8WYbBOTLMAY/ROaaXRuZyiwAFpzcRRcD1yGmR+U=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=apNzvozypDvfl+MSvi7KV4U35S2+iYLdE7MHwBnhQu76G6FAXT8jIOqLdQoXlxjvW fdL5ir/WUxiQ3HDn2WsG8zw6rYaofqeVUK5AREuOJpej8my//MV8RxGBv3ZfDDfAgg 8wZg7xp3c8QSXyzjurThvivQxeZxk56W4O899kPs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.170.46]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MyKDe-1nUe3m3znY-00ygrT; Sat, 06 Aug 2022 14:23:51 +0200 From: Helge Deller To: linux-s390@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, Josh Triplett , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 2/3] lib/dump_stack: Add dump_stack_print_cmdline() and wire up in dump_stack_print_info() Date: Sat, 6 Aug 2022 14:23:47 +0200 Message-Id: <20220806122348.82584-3-deller@gmx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220806122348.82584-1-deller@gmx.de> References: <20220806122348.82584-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BialK5Gr6LY7i1wCJNhco7oXVVXlstreH3iQsxuzTtOakZOQe2F vaS/im2YcOCpaEPRnRhbwznsplhtoaQSv9+CnR8fhlHCyatnsnlA0W+ZsXyuLT3WuOa8/1s Je6ndthUB5LhqHBWmvC9Bs0YLneOfnYNLV77EF8VVLuieKytfZKrNg70+qqTKD8YXHgCVzQ /Op2Ok+TusjWlOroTn0dQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:G0iN3smw0qI=:ym1I7aavjrz1RtWqYtRBpV vO9m2BBIb3SVdgpzyg0469An/ypaUkX4k8mNsr8DSTBOwaqmjMNiYSBz+ZFhvM8tGHKQ7Z8KT HiUmD87Bd7FYv/W70I7RgYYJ8vLHunXVeyuoDvNwOnqm9r5fRhM9r31Fwku82LMwXtonFl75Q GXhG/nkXkwIjO8h+x03BVPowzziD5UPDLXL0NoKhltLBLdKyZ69KB15Gx/z0c2FiS982zlNCo vwTpuDk0wBJ4VdJlTWyBc29GWGuWydDDrQSok1Qc7BRtct3sPzW8LB2ffiPpDH4rRxFKABpW4 fGhgreK3JZ0JmihCl+PC3Q9YKYAbWz5BfgjnECUBVO7ickw700ZdrTCSgh7UKu1COjfFM1aUT XKcDyZ1O5D6KS1z0FIwFPwDTJ+sV5Mxj0rY9OOXOON6RPUV9s+IuHnn1t3ApmFDu+yc05QISs gYv0LKPB+aW6B3jtLRlTX5p0amPuxtyQI9rZwAzCgj71Pn3XUxbI8OrxD9iGcLKKupbnyrgV5 GL+0A8sW5kJ+c9uux0DXhEQGiMIbGa+QP9MD1hJRlXd12e+VxTucoGkTenkHQ2mdi/rHVpj+T FznbbLP+K6XnVJvt/N2Qbx50/S/CPRKCxiGsljMOlZqVEOiAxFf1AhVBKyrUsPht4FQHIB1Wp m7JccXFhhKmChDWxNfI6xETbhQbo8vP7iyIkOrUVZes5DMWtKrKDRr1E8wmdCq3nfYkSZ9Ee7 1uyTuEbbehK/o78HdS+fk1b/ejQnvUuZGzDxCAe7LEv6Vkq3mQ6WdHyfNVYPn5cHmxhiPzTRU eGiNzIKeC45wOeP7zm63Ajr3ZczEmyVIumdQv+kwngnJzSm066mZ+S1n5m3kN+YuUeYSRXr1h fR3ARdqCFK0UCnBbC1RCQMwwOWJNF1RSt2xzYB3M/qD16K5bp8PLCZjUvSr/qBTyEUtxVJmO/ tnMnJHwdXfNIhdZXm4xONFsnqMAlW+iJILL9/FsrVy0BvtwbMAErauHiO1Xwuec4IcSxEJetT 6ytKw/l2QITetIAIIVBauKdkw9er0ROMbEidOgqngjDk2Osrey5Hw8Q11d88LNdWBIVkfWKPc KGi/eGuupfrh60BewRO7xiEhtpPUu90UVmhNHWUvwWrVJk4eiksK8SRzg== X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add the function dump_stack_print_cmdline() which can be used by arch code to print the command line of the current processs. This function is useful in arch code when dumping information for a faulting process. Wire this function up in the dump_stack_print_info() function to include the dumping of the command line for architectures which use dump_stack_print_info(). As an example, with this patch a failing glibc testcase (which uses ld.so.1 as starting program) up to now reported just "ld.so.1" failing: do_page_fault() command='ld.so.1' type=15 address=0x565921d8 in libc.so[f7339000+1bb000] trap #15: Data TLB miss fault, vm_start = 0x0001a000, vm_end = 0x0001b000 and now it reports in addition: ld.so.1[1151] cmdline: /home/gnu/glibc/objdir/elf/ld.so.1 --library-path /home/gnu/glibc/objdir:/home/gnu/glibc/objdir/math:/home/gnu/ /home/gnu/glibc/objdir/malloc/tst-safe-linking-malloc-hugetlb1 Josh Triplett noted that dumping such command line parameters into syslog may theoretically lead to information disclosure. That's why this patch checks the value of the kptr_restrict sysctl variable and will not print any information if kptr_restrict==2, and will not show the program parameters if kptr_restrict==1. Signed-off-by: Helge Deller --- include/linux/printk.h | 5 +++++ lib/dump_stack.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) -- 2.37.1 diff --git a/include/linux/printk.h b/include/linux/printk.h index cf7d666ab1f8..5290a32a197d 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -191,6 +191,7 @@ u32 log_buf_len_get(void); void log_buf_vmcoreinfo_setup(void); void __init setup_log_buf(int early); __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); +void dump_stack_print_cmdline(const char *log_lvl); void dump_stack_print_info(const char *log_lvl); void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; @@ -262,6 +263,10 @@ static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...) { } +static inline void dump_stack_print_cmdline(const char *log_lvl) +{ +} + static inline void dump_stack_print_info(const char *log_lvl) { } diff --git a/lib/dump_stack.c b/lib/dump_stack.c index 83471e81501a..38ef1067c7eb 100644 --- a/lib/dump_stack.c +++ b/lib/dump_stack.c @@ -14,6 +14,7 @@ #include #include #include +#include static char dump_stack_arch_desc_str[128]; @@ -45,6 +46,37 @@ void __init dump_stack_set_arch_desc(const char *fmt, ...) #define BUILD_ID_VAL "" #endif +/** + * dump_stack_print_cmdline - print the command line of current process + * @log_lvl: log level + */ +void dump_stack_print_cmdline(const char *log_lvl) +{ + char cmdline[256]; + + if (kptr_restrict >= 2) + return; /* never show command line */ + + /* get command line */ + get_task_cmdline_kernel(current, cmdline, sizeof(cmdline)); + + if (kptr_restrict == 1) { + char *p; + + /* if restricted show program path only */ + p = strchr(cmdline, ' '); + if (p) { + *p = 0; + strlcat(cmdline, + " ... [parameters hidden due to kptr_restrict]", + sizeof(cmdline)); + } + } + + printk("%s%s[%d] cmdline: %s\n", log_lvl, current->comm, + current->pid, cmdline); +} + /** * dump_stack_print_info - print generic debug info for dump_stack() * @log_lvl: log level @@ -62,6 +94,8 @@ void dump_stack_print_info(const char *log_lvl) (int)strcspn(init_utsname()->version, " "), init_utsname()->version, BUILD_ID_VAL); + dump_stack_print_cmdline(log_lvl); + if (dump_stack_arch_desc_str[0] != '\0') printk("%sHardware name: %s\n", log_lvl, dump_stack_arch_desc_str); From patchwork Sat Aug 6 12:23:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 1664243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=Q7H8ItP4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M0MHb1c9hz9ryY for ; Sat, 6 Aug 2022 22:30:19 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4M0MHb0CxLz3bYG for ; Sat, 6 Aug 2022 22:30:19 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=Q7H8ItP4; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmx.de (client-ip=212.227.15.18; helo=mout.gmx.net; envelope-from=deller@gmx.de; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=Q7H8ItP4; dkim-atps=neutral X-Greylist: delayed 316 seconds by postgrey-1.36 at boromir; Sat, 06 Aug 2022 22:29:32 AEST Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4M0MGh5SvSz2xB1 for ; Sat, 6 Aug 2022 22:29:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659788969; bh=UovwDaLyuTgPejCzTK254N9IC9/vqRLIfV2J6pi3cos=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=Q7H8ItP46o8LIoJDuh1iGlOJ5y9GGgazEK7RJYgT/DOTOkrrXAAyDVymYm3uVC1ke mq7tQhBF/3U0+TBPL4O9qMwB+HMN0RzS9r2lJWLX8f+H09nvaSsyEkhN16DEfxY+Wx kEWtF44crocOFJv61b9r7otV0N1ZkdjPWHVrz8NY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.170.46]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M4axg-1oIePp13Oo-001li5; Sat, 06 Aug 2022 14:23:51 +0200 From: Helge Deller To: linux-s390@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, Josh Triplett , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 3/3] x86/fault: Dump command line of faulting process to syslog Date: Sat, 6 Aug 2022 14:23:48 +0200 Message-Id: <20220806122348.82584-4-deller@gmx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220806122348.82584-1-deller@gmx.de> References: <20220806122348.82584-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:H01j2TQ/vI8Y6o0FFlkaFoyN427aLLFHAXOwrAp0nDGTiiV7Nq+ uCJbOe9koCgQtLpU+9nuzPCG4KZT80QhBUZIcSt8TR3Db2qFjWxViCvSQwg8RhzhInCmpzZ eBUxsUKfOuB6yt9DaricIZfE20DESfPdSECZhDaFmcR9xcYAqzupvYwEa8fNw2k9cHRdiu5 G0mvj5ArxQ84YO5uGzIjg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:rQUPXiTU1I8=:7PKtSH8ndyXks0Q4J5/42M 6BpD/Zd0iosHv8OqgklN44LS3iUMW2oPpidPXm0KMCZ0gyyhOxosZUw8pLcrvrD2ALtv0QLdY 1m08/9pWeBSSs47OFgKTNuuRaQ7E7xDb4wF2bM7IMf9bXD7x/u0T4ws0ArPywnYvSCqrezJmo vqyPY2soK5y4W6M4pIHuYw0L+8sAbbPKVY27gRwGI7TN0lAeLJX7KBcaqnxjCjsbev7qc5UH3 p+vnlwo1aiL6ahbbkjVXyh5X3V8X/K4gNnPl2IX8uZgWSYwLkySDeUJr4vDFypIOf3qrqt8QK 0aaWu6WWyHkWJQ3ODUJUy1CE7khrCwx6+34hjASVcN7bbyTmgfLV491LaAOdvanzRZZ/ZsvN1 UJ5yiwvwUO7OeeA+F+QZRzKliv2GfFyrci/EVLmV+m9KzPXtzLZL82FM4iq8O8P11BdP/GRN0 N+8c9gjbqinA4CIhL/WouyppqVD/jcKaQ+0Oe9sIHzNPX0fgtji0o7hxbsDrZrQQhBuyo64O8 s3TbJoAQCcTgdUYh5cc/wd84JAk+HUKSC7003yigVqYbxJRNa2ios0l+ASfdYdY2jZJZ6Iwj4 7nvYhdJzMgZgogC5ie7vemRr/5KMH++F4LgnxQ9ajPg3K68jy5TttpKkahZmDBlAsJ+kic2zq Tw8YPvL0Lc20jBSDSX4AMXHdJPINUYPZlwf7smHAXzjMm3Hw/e9E2i03WY45IRPoyVMDzi7fo 0adadltlIT8ZvDI/CNUzi9SDgtxgIGHDL5Ye6TF3bPvmM2jntZZbRDEoHc+sh1c1Jgg+XNiLq 8DJ7SpgcvLfgQkQNFdN1NwsB0XOuRJ6Pv5fVoh+78x0Wo1CJ1tjp5Hs0jq13gfRMfXJTTvG+m WFMHb6RLsOVSkitvRTBcq4NEO2dOAgaCSgh1LXZGJJHBoC/9mlPB1rcj7dWMcDqOEiZiLiMzw F5GMDMhmiDCT038IUtnU4GlXtM4GwXjE6W5epaqOvRQ6tpiM4LU2Fe0uYl0tmtUdJxpLAqq6u y6J9R6lQrrUYWGmOTA2ELcvSbYwzWBt3xwN6TS6ohxY+KdqEx4b8e+NCihjuywZsYza7u7Svq DMBHwd/hSbT622rxDOAR3p+QpDAbC0n74J8NWxUyPaAGu+Stttu63m2dw== X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" If a process segfaults, include the command line of the faulting process in the syslog. In the example below, the "crash" program (which simply writes zero to address 0) was called with the parameters "this is a test": crash[2326]: segfault at 0 ip 0000561a7969c12e sp 00007ffe97a05630 error 6 in crash[561a7969c000+1000] crash[2326] cmdline: ./crash this is a test Code: 68 ff ff ff c6 05 19 2f 00 00 01 5d c3 0f 1f 80 00 00 00 00 c3 0f 1f 80 00 00 00 00 e9 7b ff ff ff 55 48 89 e5 b8 00 00 00 00 00 01 00 00 00 b8 00 00 00 00 5d c3 0f 1f 44 00 00 41 57 4c 8d Signed-off-by: Helge Deller --- arch/x86/mm/fault.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.37.1 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index fad8faa29d04..d4e21c402e29 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -784,6 +784,8 @@ show_signal_msg(struct pt_regs *regs, unsigned long error_code, printk(KERN_CONT "\n"); + dump_stack_print_cmdline(loglvl); + show_opcodes(regs, loglvl); }