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: 12938013 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 8D499C19F2D for ; Sat, 6 Aug 2022 12:25:36 +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=PJECBi1g+lvztwxVKF1BCyPo+0SBHxqTgbkfPt9TsXY=; b=A7GU8n2Hi+iUqv Y268xiMyUFSLdylbE5iMdTKVRCoxGxRaljNREfZA2t8b84YfIOltShs9ErhLSweO6T0ZlLgn+Ql65 U6C/FJ6cPdepw/meDaBWM1Zws+ENfYzHbWFydrC96JgkVoMMS47QY3jSujlm6JmBWfO87r/O4c8h5 zP67dG3K+AKZbg70osqxPcJ4KexhcG9qKbhsqsmmOMrMX0ZGPrXP/0ovhT4F3TaM6v9uLnO+Tllx3 umdw/OlAHWYqBaBAUDYGCgcEU4glcT0CJyIABudhmk0H2kW7ofRmRyxXeOZ/doVtWSJ43NAo6JmRH XA2FCNLuxQnEHJk1dokA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKIqi-00AuQ1-Bx; Sat, 06 Aug 2022 12:24:12 +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 1oKIqV-00AteZ-Kb for linux-arm-kernel@lists.infradead.org; Sat, 06 Aug 2022 12:24:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659788630; bh=EmdUhqjuBaZoiK7nIBlB85Ojty7fJP5lc36LTjVWwVI=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=PPFrNoZ3mW1wYAYBzxqTIHuPp7ljFxHiGSxS6WoYP3mu1RFO4RUsDrm3XmC9Dvs8F t86wmDY5iBi+l/Te5FcTUsGhRwdYfsQsqtlE8Kkmf+N7qqpQ9Gi/jyOp9pUzyb5JrE +iwLmbo+qNpj5y9IbkbnE1dACSlBXJUabP53vok8= 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-UI-Out-Filterresults: notjunk:1;V03:K0:sgsA1z+8BhA=:uYgI3h2+qGCqUH7/aNn82K F1a2C7EaZPgLQjPqegtkVYLiInLCTUtG8wD3MTLzSPemwz5IVfHZINjg0Ox5Zbe76D831rADw +Q9ILY1R/5/s0OVfWJ45cFHAwrSEUOcvtiQhBF0qzQmBetfsJ7NHV3cH3UDKHcZaVKLZ5JruN rz65uiAMa8YpAFBatczUd/XrFgtraZrBy1YAMW4O1y8MRcDDsBFufs2e4o/YQUGM8z/mcTqKb /FffqifiStutTk0yt4dTLzeGQJkNbhZsaxos/VWHdCg7tjPBV8X4p/kSSehswhkLpLqsJXF5Y Qp0lHlUVMGjCOwbDJVmmRRGu2Lh8fiwbsBuujGSw7vrvKtLjpMP+VVXdNxQGpQDuJegM6U4pA aP/PswH/PeT1JH1/qBa323PwIgRsfd/+xOOl/ncEp9bwTkkkCkDWczoJxUadZ+qLC+fZM5SZT ogA/6/JUY8xqFEHXcuMuyj6XuvirGk5Kg06ZyWXh6qpkMpTCFYDS1TcBp7wn4H5O0X8S3bNfx vD8HYjH+79yA4O1RpW+dQmx5/T6EaDO14/1OY2cS1EkefNenwmcD8zik1x7nXIoCSogDbatQ+ a9NHIwPJKf75GuNk8nwZ5YaR1o9uSXDPVZm2g/9PUd3AU9PHawKYOFVyUueUU70+1WW+bbyRz +z2OM2OPMhVAnUIT89YEU5WpHw3OJkyu1Iih9uz3ulQACWMFbtmMDnpq35D6cszBwDyF0HRHG x2JmSN5E5JMVX0h4XmSHtcEyfzlBgamABMyxryQsmZx+B4nXM33VngieS2iysPMgRDg+BGpMg zok7O6C1WR+0euQABwJCz4dkDqM51hzBvpV0iJGvMtKau0mQNOg8l9zrw6eHrqfd0UfYCeFto aE58LeGrWT/HyxbkBl5+nCcjt8O+wFeU5Q/fBRjdQUXmpxXFB2Rn672uDoxTifP/mS6F4pUXq 5vmVbbs3Kt0UoxGCn5a3LgP0cvfZGA37hG3ZIefnlVRVKPuqeaSwWc6OeMMgmPR2Kgym8rzHg y4voZYaAYS9OURChdJsr3/B/qtlS7usEICg5My2dYfFDahdZ1V6RTLpXRxpzv7/RmZaFpB8rP ihSIfoKxSxnHFUZyZ9kxtDYWQIROhmUgNbMNtfo7lTWQh9UixCfuapEQQ== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220806_052400_008947_3F18480B X-CRM114-Status: GOOD ( 23.67 ) 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 --- 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: 12938015 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 31739C19F2D for ; Sat, 6 Aug 2022 12:25:39 +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=axp6YK7ILhKowV qe8l/25pWOqG1mx0jv5MoqnN6nLDeL3bqt4IeHMgbY7ydal4/sbcgeX8YlJz3LODaLjieC2cKc2yy 6LxEzpJ6tTCJB8KZtNWiS/nhx39WSjvCW8cTxg5xmNqiqUFw62tFx7FU9JbleaGk14SC+AGbd1u2d NvPjc8gIKjdnFVp8t/b2Z5ClCMqmT+y68wOM3dgq4mAj9cuqFKXf6095Q9A+a2p2xseppRslRKttY rtdPQqj0nspymanD7I3198Af4p3XfehKv/yYWIGClbKSMr7bVo5OzdtcH0kiAn2jpqaFmhFyUuCyr MCZKS4O5/qu5HYg5GwUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKIqr-00AuzN-Gl; Sat, 06 Aug 2022 12:24:21 +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 1oKIqX-00AtiE-6d for linux-arm-kernel@lists.infradead.org; Sat, 06 Aug 2022 12:24:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659788631; bh=lELR8WYbBOTLMAY/ROaaXRuZyiwAFpzcRRcD1yGmR+U=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=WyehE8w1Jhfb7cmxf4r8c8mKj31OCf5NW+Kp+QP2am6/6DhXUOSZw6s6+iTRK7i2Y rKVfEXTH4O+4nNKfRWQgZAkHpLLJBZgCFcKMPhi/WxHeQTnOnEkSIkhhZTq3wwtXE/ mm6hPmTT8zmbcf70eNsaPwtINlweqRt9dNU09GSQ= 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-UI-Out-Filterresults: notjunk:1;V03:K0:Mu3f6I4mzLw=:zjKIeXJ7YvUUYkQQndV98C Jh5XEN7sYnVdh0dFdTGaM76btoqfgn2XjywmBvgmEuoGYsto9NV1HO/07crZkwtG8F3E/yPy2 b9JAfz1g80530g/AjEY+kX8TiKcjzd9QdOW01q7pneoQnGaJY9h5uQkhb/G7AfnxNMmSBIk21 fVB7DH81TvX8qREv7VDmcyWuGfewc2QbC8d81QCAhTmcbh7YJ931dTpJI1Sff22C189bHjCWV YlKx4AoqQQhuBIRPCFdvLOyYkZU75uoAuazvgJ/wOICxwa4oa/6T9y5uyMfh7ufvPZ1yHm6c9 c0kWsMFxsOypWGkLoW1ZnWd4oSPIjrD5MjsTWTjomvmyZOgTMEfVcJxxMXe3FLLIREdMrHn3h MUjr1gzWU0OBlasW44SSQzyG84YKxU3lXUX2DZKOSO1G30Zs3U/mD2wcC5xvNxGeTnxnzIkq8 kBY2RwHKXnqpIlA9PXU69KLch3Tnq25AaM68d/sQQkYsc5w2aoxulLfejsz83mmCetq2b2T9k tNDG+teYLYWzdP/FR8QLuiqw0QX5TIzbN/f/AzOXeBdsM4MvEei414633RtoxCARM6NlKqqqg WrrbgTYmQUUc/+1CZwwMO2wx6FjdmTQI/icTMNWZ24LoP+QjHutOGOXwStlUkGaA3k6cDPeNQ tGLvuCkUQ6wkjm8yWx68N9HgeBEJ5XAJKZYcNx8/7GyqMb0TMaGjn3GuHPeyXtoHva73OnczO dwnyH6lDuZIi7aE7cw8t5vyknR0dY+GpHCVlRJPG2ahT9/pJ2y1tvkclwry2Q9ikFzRV8h9hI ylQSq+WsMHDugXffWmv5wBPznBOlx2rLyckCUoJxpNhXf1Lpl/iLbTEHwcYgRXAuTJxkDqbvn xA7eCe8GI2Joh0+2BMUgtSKu1XfhCHqcC5zelbtBbVeDy5PhRQeEdy4rzboIJY858SUbhW4hd v9L+dcswOxIb0oqxLDTt/mbcoN8sCX2AT3rZhm5cPExW8CZ9ySXty/4T1m8y+wXqvidb1V+NU ZNTqb++QElDkvaqYPdVPEIykOMOFxhJoq60pwhPvyQWxpsJ+VdeRkkGeKcHPnvNig4OdOYE4n xrTh+fgGdUpSiwelgs2BCsT+uZSzLwxcWMD7hETBr1lt8oOULoacU/zYg== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220806_052401_571368_17612742 X-CRM114-Status: GOOD ( 17.28 ) 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 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: 12938012 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 92150C19F2D for ; Sat, 6 Aug 2022 12:25:33 +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=LspEUKZYHTbBW4h2GKLL1uuPpbTl9fwcUX522hvr5wA=; b=NposhCF7BAEcH5 ziYbdJuuHrPJgETaM5Z6fRrHIRzhSh2Ti1doOP2c/Wb1ThtiCRnz1Yb0qLoloPXOVd1HmXHs6xD6T fqn9kZLBd1JAgk84KIpTjj80ZAFczcjf/Tc8tzPRnbsytfc3HUwzJZIc7vchwrJTCi3ryoSgevauN 8e/1bU/BgG9HrtG0l/WjAad/huWRJw4OOlH+BpICRlk+8kge3Q1mKmpnnjz1pVDADWPSylJY+Ltwx L3xeMyQGEpHjodSRSvOUwCve9CvkBKLJ0DlJMs5r3C5x+Faez8EZ8OtRDapVlZT40P0DDwY+wZm5i v7jjbz/esQFFe/Qhc78g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKIr0-00AvZB-St; Sat, 06 Aug 2022 12:24:31 +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 1oKIqX-00AtiF-KZ for linux-arm-kernel@lists.infradead.org; Sat, 06 Aug 2022 12:24:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659788631; bh=UovwDaLyuTgPejCzTK254N9IC9/vqRLIfV2J6pi3cos=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=a9fwassgbNp/eFsORC6vomzhKQDhM2K8+UJAIwEB9sRSM/3dzp1j7fyflsow33MYF 81aazw3OzfsNl6ui8/QyG4e5LKsg7vYFTm4tOyYaRVdNpFBhk+REgBHtR4mBbH/8S9 3Q9m7MENLt3DMs53shyio87/m3N1AzEI6lAz96U4= 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-UI-Out-Filterresults: notjunk:1;V03:K0:ZTF7NKTDIkg=:V5IrzQOrGpOVpaB+EZkEAm wsLFU0HPEtGwLzQNTX4xKiZVrc1MAly/s5sqMsqILOr1GFvamLJs5mrITSLnmv24tiC81ac4p PJ/QZfSZmyddGeoZ6JiL74GpJYtsZb+wOVukOtbI3l6NSjn1rhaxdkat1O4PrDMnfkOok1m2g t7HjwUnKCrg2TxT42zVGmIttLrMD35zURt/22hIuHHSPU/ZO1UVVaiD8j2h1GZAJhrZEy2Q38 R1IVgO9JGkYa+xYEg5URMrIJ8KepjZ+b4GnyWuvHPTS2Bd452qBE/2qGeOfYJUmj+EZs21vQv vKmiTJLRVc9KrM24QR6tb+m0L5xRksLZw1GfIVqNShWcFsx2hgFWBslQ+lY8aCx0K3UScX2E6 nPLZUSN7BQNWyQhRF+ayChwBRmVMWCGlIE4xZOuIoVLxOqoYn6ZrHRKchcWMwnPBCyHFt5Sxy WOj20gJYiCvysK3sOANSSLVlL1lU8Gvmi5ql7bIOTCOe5v1K5zHaDUbRoSl/p3VgaPXCGwJKp HfXXa9L67CHzXhnDKta84f1rAPDzwTdaGRTSOA/1iA3w+fTG0bIeQL7cDlRj0/Ali3uT0lXRq nejZq+kgx0lvL0h7dnk9vUiuVEfBmTNic7jE9hOcTNF27WV3P2pTQq4ZQrL6V519HQ2A5ER2g W0qWgOqqO+X0pD1zVoy0tpuR7vA5Mo+ZXAQzDdm/WeZRi4+NNFXIZUoZ2H8G1Htc3U3JTHLS/ 57Mq/4jVyjsG6ZNYGjxc9WdJI51M/QPFnvw0qQ3VF24l+YYrqSdvA4ssW4Xs4WB+nIp8AGpeC vUd+AR4Y9QtSwDwEkzQEvVWWEgbRpUUkPmbUpqlGwouTV/OoBwqSN2kVaJV+jVBBdjhcOz0h2 dYotQtIWlRvztIDUBA0Rnlz8Y8dA60P+wMhJrMKVXrL7xWToL80BG5fM6h2FOkgxbPs3ShCrq rYV6VgQV5wbCshM5AMOnROdzeFIx2VVrDnaEcd+kADRRbeI8Btg7sEZdSCOZPyDGbCzYxwqIe 4FWCjuAkbzgoKvVeR8djCtioKWsyhRFSjmzlANc/2lCLleM53lo2kXNjD5CyscAr37vMHgh5d mmzrgSNKS+PGv5ksMyyaCwp95m5BguKuzWtK1ksb3Xr3XftOpw1NtWW8Q== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220806_052402_006531_380CC5D4 X-CRM114-Status: GOOD ( 10.00 ) 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 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); }