From patchwork Mon Aug 8 13:09:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12938783 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC4EDC00140 for ; Mon, 8 Aug 2022 13:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RTagQyklFq6yUXdpouKDMcqeFRPKm8u2PSX4yB2vrkY=; b=OJf4IXgM/Mm2iD jaqzXH18g4LaCSlGPni9KSGRHD7PjcDzNbMNRoRlXkzVay/jO6uVZZ8RhEMSf7NTp4/8c+zNrznA9 +3rJetNJz5loCm+co5Eo6ZKPmfpUxRPQo++RNEXHaMnvV34TyTxSs6ZXrZVThETtCajvQmFkBT2Yt chRmWm5auXG64DlZVHQj8djvD7CBZnjfx/+tzlmMAMkwjK0Wevq3MY/LkxBU6SCsfaxx2fWv5Kgkd qrxDz6SuUgrfPGQqShLCRurDkaagE+BSE99GLoJ+lAX51xXQ6Z+LQSMoFrv/tsepRchjr+251uoJF 8/3aihbLB7N50UkJff9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL2WN-00Dy6N-FQ; Mon, 08 Aug 2022 13:10:15 +0000 Received: from mout.gmx.net ([212.227.15.15]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL2Ve-00DxZD-33; Mon, 08 Aug 2022 13:09:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659964158; bh=og2ZdLLtR22r7awQb48gxxRxQ5UEYe2MvvpX6puOyYg=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=e5TFBsOqdDo6sAO8ndmxdlbIX3HdCrNNsbgl74qJNkqlYPORLf4+kb4WTPHUgQGVY wGSBWGgzPcvDyCWAtQXBcdr5FUkOLYcp2fjPNWs1qEH19tKUKyQqs1ZhQdZv6F4fGO Gdj+f6sm8oHv+raOhdWfhiN7ubzcT9WvzSZaRfT4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.169.184]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N95e9-1nIg8H1vCp-016AhS; Mon, 08 Aug 2022 15:09:18 +0200 From: Helge Deller To: linux-s390@vger.kernel.org, Josh Triplett , x86@kernel.org, linux-snps-arc@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/4] proc: Add get_task_cmdline_kernel() function Date: Mon, 8 Aug 2022 15:09:14 +0200 Message-Id: <20220808130917.30760-2-deller@gmx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808130917.30760-1-deller@gmx.de> References: <20220808130917.30760-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BUhyAXuWPafeJuzDm8mq7jSWYmyxtYv8WO0ZCcQgBQNw8t55U3c GYOoqStr+xKHFwhHmRsSa+6pVg0jyVC9IIjlX2TpRgh5wPuGFRN6AAXC1ubYkpk52CNvt4S 9CifaVKo+flwBSitpkkJWBv9PJDHEAUGWgt6oNAiuQf7zRWlr3+QOu4W4noco5xxU1FlRZq Gr+bZSao1nerycI6oObQg== X-UI-Out-Filterresults: notjunk:1;V03:K0:W6pVbxkhYHE=:5HAS2Z/J5tPWiFF1HYbnNC kYyVd2x4ivnpjqDK1wm/+XtQtHETHBaeG6a88u9VjFo10m9vuD/o8qp2AeNe6kiF2WC4kZYal 5+eaYV8LMqZ+4T01Mxd9ab/5nRl6UyaDdUiOVmj3NIM76U09/GBqilVAbfscbup+7/Zei6iPy SX8aLOUt7bxZNdI/48/vLv1zmL2Sa7KykpgMVnVoDB94xbtpW0iDKqhGic8Nz5l45INROq6og /lM0ZjX/bl+rum+lc7gtfTIprO6+WVlnweqRwPgPkty9Vr3pSmWBbXBxOxm9iiieuJ9gw02mm COBYiDkyHMV9uwhwESOJ+vXmMeoo9Hgmoa/eihwA3EWmkl8Gi1LY3J4lK4XrPCSo/eE6/3cX3 mwKGQAaYTAKfxk0Jas55UWpzQg2ttSQjqQ8j5xBt8q1pVMNieumoXhvIj1G3/7kIf/3byNdsd 9lP64NsjTn68EnKveimZFT2k0+tcNl1KrR3d3lgyJLt4UsDBQc/qpooHBoUBKYkrhh6FI8eC8 sJWHWJ+jx2JYdCCIvMud7vOGbwDDzCax5lSFSAK67HzQmr/GuGQDzymyNDsoFxOpZ9kQL7+2F c65RVe0UadqJMtO2gpKvIQ3ac6MLM8ootrtBDknpU+Dyra0hBqEHqq+rVLk1oftd6QYdUPfuL ZJZj31xIs9WOsiDkyoGQZHTm9mIF82+NgRo4Kv/Mb3UBDpBeIROl9pBgaJgJhDia2xjNFIIh8 McL5H3QRAvyrJ855qZr8XlGzN9Q7U/NwQVh6NfInq4OAna2UJvGTk4iiDtuAvuzYOg/35tgwr +sRaFEpSkuyesjr6yb/4OMyscqcngLKl5dPthE7ouLCybxqNdedi+uIdSMl7XaSO7idkourJJ gKAZqYAYT5vTexy639dfwrthHd+8QQLyieIm6khESxgXrVFAXwPXCj5GNhlp2/nRkpc463tpi QS7T9wUP5P701eKJopzufgtWwHJHQjnTqwZj8XPspRZ8JixDAZxw7di58Qq/BIc5HDtNuCNQs 19kRq87IgG/aL6GhgdPzONdvFd00WLm/5GpMUYHqObnIFjA6UiXqOhP9P1IZVmf2dKOzRcKhq vjBvgxsHrbl6y7qW4sgdTlMVf7aPQRSZeQpFt1fVaBaQDgC2maCDmlgug== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220808_060930_465093_48482738 X-CRM114-Status: GOOD ( 24.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- Changes in v3: - add parameter names in header files, noticed by: kernel test robot - require task to be locked by caller --- fs/proc/base.c | 74 ++++++++++++++++++++++++++++------------- include/linux/proc_fs.h | 5 +++ 2 files changed, 56 insertions(+), 23 deletions(-) -- 2.37.1 diff --git a/fs/proc/base.c b/fs/proc/base.c index 8dfa36a99c74..e2d4152aed34 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,57 @@ 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. + * NOTE: Requires that the task was locked with task_lock(task) by the caller. + */ +void get_task_cmdline_kernel(struct task_struct *task, + char *cmdline, size_t maxcount) +{ + struct mm_struct *mm; + int i; + + mm = task->mm; + if (!mm || (task->flags & PF_KTHREAD)) + return; + + memset(cmdline, 0, maxcount); + get_mm_cmdline(mm, 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..c802bc668656 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 *task, + 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 *task, char *cmdl, size_t m) { } + #endif /* CONFIG_PROC_FS */ struct net; From patchwork Mon Aug 8 13:09:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12938782 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2AC23C00140 for ; Mon, 8 Aug 2022 13:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Bb9Ki0Ei9EMUZmisp8l4+bMifICoQKI9u5eejzF8sCs=; b=Kv6tcd0cC1zNKb REB7B+lUr/qB2+wRiOlEwNp7G7KHk9JO7iG/QU7uEfyNtxDC8Up4b83GUgAYH6WetRHzvlFpp/mQs 3OXE4Lf0WZHfS5aPl8yDhquZR1lROCfFICW3BQLiJz9ZBCeLhnYXGF1BW1UPbBsS9VBoRhQPz7E3p y23ImPfNP/TS7tOxVoeMZgg/8V6hfo+qDK9YHFnttqGHKlz/2IqXsZSWGEGKm7ce3E0MKTrLK3/QO qCPXDrLRvrL9VtPq+2oPIeE91siJG/xgKEk2IYWkvCT/QKK/YmTfmgJ5cWBhVkFGENdZLiwP3sCJz Btkdj19eOjACE1FbtlIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL2WB-00DxzB-JR; Mon, 08 Aug 2022 13:10:03 +0000 Received: from mout.gmx.net ([212.227.15.18]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL2Vd-00DxYi-BY; Mon, 08 Aug 2022 13:09:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659964158; bh=lELR8WYbBOTLMAY/ROaaXRuZyiwAFpzcRRcD1yGmR+U=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=YARkRCk+edkIn5nZtTwbKK3+c5x4yjVNPDa9GujrX2humxefMcP6U/5piDtobCt91 mE894Vzo2J/rqBnP+M/O9/i+Xrz22svt5Szx2tjzGcOVwE4jcCJ2O4SXL1SGq5zwmx OcJCGuVzeFwDEtHtoszNgMaJ+SvMji6yr7O7AwqE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.169.184]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MGyxN-1o8AKD2zDf-00E4Zm; Mon, 08 Aug 2022 15:09:18 +0200 From: Helge Deller To: linux-s390@vger.kernel.org, Josh Triplett , x86@kernel.org, linux-snps-arc@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/4] lib/dump_stack: Add dump_stack_print_cmdline() and wire up in dump_stack_print_info() Date: Mon, 8 Aug 2022 15:09:15 +0200 Message-Id: <20220808130917.30760-3-deller@gmx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808130917.30760-1-deller@gmx.de> References: <20220808130917.30760-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:dyv38+4Ugz+oNJYhEqwA1WGPLQMQCHxH7gYA9DzhxE1ZyTHPUeX lgD4MbyXnzij2je0A21JveizFDJ0RysmHlBxi1vdTStYEm+RmHzoUuMstEW+hD9FO33SxJr oP2WdouS9nQ1WcoKEklsuUfDBg9/nB9mx5tSBtp94vcEnDi6cGYPDjwHjZ/7PA8qYfqxH+H F9wPqtQXlYJ80YG68DQag== X-UI-Out-Filterresults: notjunk:1;V03:K0:RpW0RFU0Z6E=:vHBeUsc70DYciJo0r3uauF MGJOW+2JX5iPyl7bzACYuZzcsgE0KOuDtO1K2Bppk4muzBADa/0UwkNWZnhnxq9gctbdzfM2F CjYlu/8hoQK8Rp2oi6uDjx0cvEw7fMo5WqUcUNzy/eq+XjoGQFk9oFfC6s4hJjWMIRGQtNjNM QcPSX8jSs3qP0DmNaFDGPankZ4Q+5EQr/+5SXjaSpwz59qzcyhuXKBV56vrYGFvdclmephBIq B7oxtrb2uaCWI+kvsoNLs/zrQv1fWspOyVBYQASk4fWO7nDttW8eUVv+FGqWNewFLKdxYj1Cx 17xFxjhqi6jg4+258yvMd3QGes7U/5INRI5An1vrAxJH5fzxnwNa5zPcFWDdXr6824deE2ODO OnIvUA2lLkfbK+8WKDyeLKZvsnoifbZDBBXzHpy94LePbuI+4LeFGkvBQAXgWh89djmnICx+I bklL2SCdn6+Dj4mOle7BQzRhIdtZGFKKjmcbGFkOQ9mhbF/AEA0+p6vxkBh3l+Sg7YCaET3rX Cvn6uoFNHsLPmIGhUZ9naF1Tg1Utleqnayp70ND3Y/8G6eYDBwrdmJ09KCKMJLksREGa9gCLw QGLTi8C+auExK41IXHRYB1YmxVCytlyQkZpRSoEB0K4iKVRvdBlP1PMJMsR2YfYUG807KDgnx vytnyNGsCYDOSI8kcQLPdUWHRcUehw5OAt9bVZBM09KlvsDZOafd89xsjR8n+hQLQDgQXIv79 EVl4Fwge064DHAD7FCCY1/yuzwgRafYs3caT3EgYOx0FP9ExsGBPef5/Xjz4gUcxhQ7xEAvEG 1Yq4ZjOoSQ+WCbrKx2ftLQmfGPZLqor0mdgKBg/sfVEHQs6h0Qs8QYWVvlhaQIbWLavN+/5uV 5FQmjRtWTcUL1tqvnWnOjjYl+4E41TpDG/r1W4ZyXt6usjTpUUKxzAbU1plRO4KLbMjfe6iGo OAVHd7w4z5xUq0GYnj0ApSE32SJ0q2AEhGU1eprIAN5I2PHSYdUvVzglD8DT1HnByn9qhqba9 GfWGIRaNOFib7OQV8Uetfbqt4SniAEFZaEgLv2Vtvka4Z3i1FSZNu7FnWZKiSg3tCWc1Z0Rw1 twVCPi6Gum3G2ewQ5/3id79oC2uC0VmtWK+w4iwrz3W4P9YWwp/BHym5w== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220808_060929_732247_9DCC399E X-CRM114-Status: GOOD ( 17.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Mon Aug 8 13:09:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12938780 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4ED31C00140 for ; Mon, 8 Aug 2022 13:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uwtHdX+XFDv6DcgJ9MrJFhgTeVDau9mWb5zPlxejLFs=; b=dxzL+QnSnbhlUk nPEjUTKmmWSOEe5g5eg8GImVpvNdNk4osdjt5Z7sNWlngiim6uq3ZROqooGgdoEiNnRIOm6WV1ZRL fZ7xqEQ6u/cDNwOAtgAm6u77BXlLRprmnuXJLvN+NC3SUR852EO2O/KclA9LdwawR3COTFD6AhMC2 Hs8Bedow+SLuoFP00AR8IPXMNGtMEv9PbjJE6ceAXBnJRjD4My4GukRXanpairhcFKtp2KCxSI7Xf o8nUv3jsXAv64Oj5vVKfviGrSuOjhwVcVCTk3vzQ2u4qzcvKKfkHeeH7KOilxsxd7iAVHzt0YF7wK prXTrcCWQNEVZwgO08Tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL2Vl-00Dxkd-BH; Mon, 08 Aug 2022 13:09:37 +0000 Received: from mout.gmx.net ([212.227.15.19]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL2Vd-00DxYo-AI; Mon, 08 Aug 2022 13:09:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659964159; bh=P4saksYO9CTgO6X6/2ySNBwjHK+p2F8Ba3kmdgwmNIo=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=cF2sSQk2IC+/YLMkYSNiIW3FHdR6BCkRcqQvX1zhiuPVvJZQL1UrHfQmOVUTMjj6b FvKwio4C8cpMCRUi04gaB1KTi2Ids9kAGjqxILLng/okGBuz5QsyMdbuxqYSgSAwQP Qei1jnz9/jUKpFiS07EcRGUNeydXObY4538BoBpg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.169.184]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MiaY9-1niySX3wFb-00ffdW; Mon, 08 Aug 2022 15:09:19 +0200 From: Helge Deller To: linux-s390@vger.kernel.org, Josh Triplett , x86@kernel.org, linux-snps-arc@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 3/4] x86/fault: Dump command line of faulting process to syslog Date: Mon, 8 Aug 2022 15:09:16 +0200 Message-Id: <20220808130917.30760-4-deller@gmx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808130917.30760-1-deller@gmx.de> References: <20220808130917.30760-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:louBvz2yR4jkTgo627u5H+l8UG9i2dYFkwpu3hE4RDyH+SAv5gu 1uZi8tHKHiOS2z+aIDclKc2Gke5YpmvooMGsYPIvvTBUDLFBLu/XMyZQ51/Dtejtxc+QadJ l6R1uEv1BxzjnjwzGKJ4+JSXGHaEQP2kmpKZEATjwMbEGaQNBgoF7RMSFNCH1Iuy+qHsS1Y OncxQEUpqyh+9TkLLFcSQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:/dBBLCq2604=:Ce+jE4umdoxfrr2xtC6+FD 9O3kqH7oa2bzIwUT1YYtDtTQEvjEhaVKo2L2/eGbT2IbjEdhpirm9T0qXwaS8uzvrD0FJRIZw /EODphFxIOJGzVw0fuYQHZI0ZAcTtBvojZlM6yyfpiwjh763kbKp0Nf4Kd7uDOxmmxxMPi8z1 GtEVaE22A/cY3CrMzlAFTGLJNVTdithhoPSKmMH+H/dspYeXPBV2te61wq+6GMKdCeOXoHoZ6 X9tIc3R78hZroZXnxNxMcztgr+/i+mIq9/myRT4TyMtkMDy/CMLQggqNDipcpP7JsSI+XhHVy aTXC/MVoaFadlbKPnAXgxXbmQLdaOcGu0mTD9WB5CRuEkUTEx9pbcVBnvf9nnTSo1tgcB54GQ 567YrvWzPXosPGu/cayPmIwVVUSNuZ5zr1yXeDUCI5f8HQMBYBmNbUAMkikIL5kVcDbYb2YMI hNSrCk47oZ4312cFwP6Ud7d6KoA+kYK21Q4bp8tIX92kpBMRW6WSdhcV268wixbT309dQWIxa H96ZcddQnEkOt3jcj0aMzqLSLYQw766tL+/KjfAdR7l3jFSj3Yg2DI4yNicwrEEkw8fJWv7rl wlKXHWUczVdPUWBRlSn74V0ntrGghvFD2o3+klrzp2tY/75CdWNFrNg+Cd6MNRg2CUqLr+VA4 5N38FHRPGmXWuLUWZDkWdzThpuUS6illt8HujKcgyWlFXZiXcicnbYZ3OCeCdSNiGExN+nQ2U lQc8It9Q3AO+9RcxASCHGZyxWdLd33hXp5SYtUiH7loorc3dPaUVSZNaGjb26ZoeXKG4PngWv Qbn5/7A27Ug46B8O8gzQnTWVbneEpJQyQ4E9pt7UPQCX4aA/bNl5Rf6JtMXV3KomiAtQI8wiA zKWpWLt+Bs4NHtMzYP17ep8v+W43ADKf5lXrKD/phCMrFWOU3i4o8lArtJrhlBLr9k9wqag9+ j3NTSY6pz1A76oLcPNwDbU8xLvf/BNEOt3eoYWmpQrcCFYHbrcdsNw1ManLkSIbzQpYAWPVL5 wRfSd6lP/K6CfEQwK3n2ktHHqe2GTe0zSmwdXf9KJWBXstn+yqCCXmfEcDClvc4/4VSwGiEFs G6KUCv0LJ8uIV1Qq5IN99V1fkf+BU2+M+iYVSsIq7Wft3PA+QMTNnNh9Q== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220808_060929_692516_5F389F96 X-CRM114-Status: UNSURE ( 9.35 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 ... 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); } From patchwork Mon Aug 8 13:09:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12938781 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC5FCC00140 for ; Mon, 8 Aug 2022 13:11:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TpYklvbLnUaLmO4nQoMk9fcihQ7apcYAdLdUUtpP4Gk=; b=SKVjM0vtCyTtcl L/eANxvU4a2FzZ4zSxjdw5SFO2OVe8TyZq4A4i853T6X5ynCV3Ckea9EuPx6gP7ppP3ZeA2Zdeznw k+8eI+mgnl0K6xWvtE7YKGRb6iVgSawpV1QjvqwHKmr2ZXX88udz469QRhrM2U8H8KSBQE7Fa/5by /r/XLZW+YSXeHnAC6vwbzLu0VjZMX1wXACcqu/u0YF0GUCgCTEQPWDhoQqsarSlb9YezBY4nuIFi3 HoOBwP6KvR2lR7WGUqCdkMYkE8+DRkJ0CJo8urRIU45h14Re8MjAAl6ptxc+rgABE+GMw0O9QugXJ qU8mqN7QIWRCoCqg8zmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL2W2-00DxuY-5m; Mon, 08 Aug 2022 13:09:54 +0000 Received: from mout.gmx.net ([212.227.15.19]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL2Vc-00DxYp-Tg; Mon, 08 Aug 2022 13:09:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659964159; bh=0M5qpS13eLgzHYee8MKVxWGYrt0iQg2yqGtZwU3aGdU=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=MAJJpLOmv5dP4WWUjz3+3k/mV957rgW3/oPnz3WDvdF55JVzYl9+4da4nUIyEQde5 fp4ZpNL1yylkjW4WMjOYsxEI1SbQVi0Y0V6evCsQBgpPvCz4S3PP29D3vBuNI8w955 FdyD3hHW46JGuDTJWIudpTSlqEiAzvjdMRSuiaUg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.169.184]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M5wLZ-1oJ7ci0mt9-007QkE; Mon, 08 Aug 2022 15:09:19 +0200 From: Helge Deller To: linux-s390@vger.kernel.org, Josh Triplett , x86@kernel.org, linux-snps-arc@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 4/4] arc: Use generic dump_stack_print_cmdline() implementation Date: Mon, 8 Aug 2022 15:09:17 +0200 Message-Id: <20220808130917.30760-5-deller@gmx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808130917.30760-1-deller@gmx.de> References: <20220808130917.30760-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:qbhdCVDdOCub1ozqXacRBFmeXEK1oHZl6SIb4aOtZAfxd9npLiz JIPE+2fdpNF9wfsoTc1Fq05gbMQbVssIrx529rpnx38ZZwh/bdchIpZuTlXNOU8kORBr51N OUttWVrlobZJh72zp3/GOjg13qfmgf2jAdXfTwFqcswpTzOPz3Zb1y+E+QxB5Dq5yNsGa2L /AiGHtqfm1EdEzr6qa2PA== X-UI-Out-Filterresults: notjunk:1;V03:K0:UBgKY5ubY/o=:y4mAM+/YC+hjlH357pzhLS S1Oo26dgQQi0G3GNPLIWloPIzSYdEv9y+fkRy5kKq6Tapjmbzqd1PMccmB4swJ7gkoS1VPHsv B+/aK5aoO9wR1huwRixwjHFzFW9X8bXaaCBe3tfJgOzHfGM/x6I4UzK8y7/gSjSKV3bNioc4d a23nO7jfFxECak1p9CgZc913l8erOrMSXdvRqbOyPa+NScOFlMnCIXJiN2JQP9vOuFyBpbUCd eNwWTHyTDWQ+TPta9DeTql3pDf9MrSx/ekuzbLuXnxvcnlV6/QKPt8G745S8Ig7pcKDIZA3Hb keRlQimwz0qP23/7C7kNx3ttYi+EEpKwTPp+mW64ic366tf8+14YNjE/4l7hghbSJIG3fsF/m 4F6w1QQfKgT8rPxu8Xm+UKVQb/kN+jnPmpWZQc8QB/QTk6TGeNu9usIZGvpqTsA6B4EjFfcVy c+xgsWyLN0iVsIte/kRAKjFiLBWTxJPMu/FOAxAEViXUxdYB8blZUMkaG2PeBtnTyFbqf6PtT m/ppniqaQYyVUvgk1Xvv29qBG+gGuTEOqnL314HzgwFp4woejXDpeTePfROdyGY9+Lru4yJKY CEYAH7dJAlK2Xs4Snrq3hpQIcEwLUqH1g7VahcqtkZV0Q69KnpmxUaEDgyBLfu5qCRv+JIDNj HvlJXR9n8yTIf6Fey5BpfmI7EGOzQ/mssNzrWX8MzX0cDupVg+Cbk1hlgPkl+cwaCXTOWlOz5 m+OPAHfwa77r5nTBke2ofYJ51SkCtHh0ukFqur0Lzvt2Cg6BRQvQpHT9asgfRbd7tVlOmTJwf 8kl4XJDBAq0Qf/BxMmbHkYrEDZm1I04+HUjy7j58P5LiUZuLMWceAiFVHUTPOHg4Zj7hfLugL VLIgvAOwrOqjINCRrmkB6V/lN8vbnrRcaTfxGAYfFmdm0zPIOFJLFbRadQE//zskDBdh4+vCD SV8OZMvI+eCduWQJUXhMjp2yp7kTN9+hRq/abYJqStonqK9U1M54jkuhk3A+PXjDPkfM5SN8W 7Hf8quu804dluN9yRLhnD3XHGCEErG9sCGDZ9CfjBhkqy0qrOm6zTa5bJd/swDqzUCx9Bp/Hm LWtAFNsvYuYAvaE6CcXszUWJFsPIxTycLTSZDmdOHyy1A9d0bv5bV1Xfg== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220808_060929_463054_1ED50712 X-CRM114-Status: UNSURE ( 8.16 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The process program name and command line is now shown in generic code in dump_stack_print_info(), so drop the arc-specific implementation. Signed-off-by: Helge Deller --- arch/arc/kernel/troubleshoot.c | 24 ------------------------ 1 file changed, 24 deletions(-) -- 2.37.1 diff --git a/arch/arc/kernel/troubleshoot.c b/arch/arc/kernel/troubleshoot.c index 7654c2e42dc0..9807e590ee55 100644 --- a/arch/arc/kernel/troubleshoot.c +++ b/arch/arc/kernel/troubleshoot.c @@ -51,29 +51,6 @@ static void print_regs_callee(struct callee_regs *regs) regs->r24, regs->r25); } -static void print_task_path_n_nm(struct task_struct *tsk) -{ - char *path_nm = NULL; - struct mm_struct *mm; - struct file *exe_file; - char buf[ARC_PATH_MAX]; - - mm = get_task_mm(tsk); - if (!mm) - goto done; - - exe_file = get_mm_exe_file(mm); - mmput(mm); - - if (exe_file) { - path_nm = file_path(exe_file, buf, ARC_PATH_MAX-1); - fput(exe_file); - } - -done: - pr_info("Path: %s\n", !IS_ERR(path_nm) ? path_nm : "?"); -} - static void show_faulting_vma(unsigned long address) { struct vm_area_struct *vma; @@ -176,7 +153,6 @@ void show_regs(struct pt_regs *regs) */ preempt_enable(); - print_task_path_n_nm(tsk); show_regs_print_info(KERN_INFO); show_ecr_verbose(regs);