From patchwork Wed Dec 19 23:28:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 10738283 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 503B71850 for ; Wed, 19 Dec 2018 23:28:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F87D28864 for ; Wed, 19 Dec 2018 23:28:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33D40288C6; Wed, 19 Dec 2018 23:28:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3A8E28864 for ; Wed, 19 Dec 2018 23:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728582AbeLSX2H (ORCPT ); Wed, 19 Dec 2018 18:28:07 -0500 Received: from rere.qmqm.pl ([91.227.64.183]:54833 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728558AbeLSX2H (ORCPT ); Wed, 19 Dec 2018 18:28:07 -0500 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 43Krcr55GBz6R; Thu, 20 Dec 2018 00:26:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1545261996; bh=gYRrWhHGPBss3VHi/c7ZSqwJ8uekXcG+4YJmVN3ocE4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=WXODbIDFkm/EkKgBsScvsrh/Prd10gbRaMWVQYlFg5xdzjhfkFks0lqXl3Ly4dNLI Fv8isT8rFOOxwRmsyjAPG5JMC9eIAzl9XLyUKk2/Cjs8vm58uWv/IVeEtAHCMBjGsV X9yKxV5LEBHh61JnYxYI07VDUwz+ttJf/DAFtfHCGsTByqRfDDaiZSPw8UyU9NVYMY dcFuZ8c6u/OS73CuZWLuodpq64vj5e3ND1cmql/QJ71+sfQmDlamIsZm7rbi2jAmDz GTAvDIU4HFm2oClDVOmkrpg1AZT2PJq138ZuPmijE1P/mh3UPijFMSMGE6jE3FEIoK FmWknnyhLzS+A== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.100.2 at mail Date: Thu, 20 Dec 2018 00:28:04 +0100 Message-Id: <80bec689c8ce0d46ef64f0dbbee349b54dd4038c.1545261970.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 1/2] procfs: signal /proc/PID/comm write truncation MIME-Version: 1.0 To: linux-fsdevel@vger.kernel.org Cc: David Rientjes , Alexey Dobriyan , Andrew Morton Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Keeps truncation working, but also signals to writing process when that happens. Fixes: 830e0fc967a7 ("fs, proc: truncate /proc/pid/comm writes to first TASK_COMM_LEN bytes") Signed-off-by: Michał Mirosław --- fs/proc/base.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index ce3465479447..3a3b566443e5 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1526,8 +1526,14 @@ static ssize_t comm_write(struct file *file, const char __user *buf, char buffer[TASK_COMM_LEN]; const size_t maxlen = sizeof(buffer) - 1; + if (*offset) + return -ENOSPC; + + if (count > maxlen) + count = maxlen; + memset(buffer, 0, sizeof(buffer)); - if (copy_from_user(buffer, buf, count > maxlen ? maxlen : count)) + if (copy_from_user(buffer, buf, count)) return -EFAULT; p = get_proc_task(inode); @@ -1541,6 +1547,9 @@ static ssize_t comm_write(struct file *file, const char __user *buf, put_task_struct(p); + if (count > 0) + *offset = count; + return count; } From patchwork Wed Dec 19 23:28:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 10738279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F972924 for ; Wed, 19 Dec 2018 23:28:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8091528864 for ; Wed, 19 Dec 2018 23:28:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 726A8288D7; Wed, 19 Dec 2018 23:28:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 176FE28864 for ; Wed, 19 Dec 2018 23:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728615AbeLSX2H (ORCPT ); Wed, 19 Dec 2018 18:28:07 -0500 Received: from rere.qmqm.pl ([91.227.64.183]:38630 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727159AbeLSX2H (ORCPT ); Wed, 19 Dec 2018 18:28:07 -0500 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 43Krcs064CzKh; Thu, 20 Dec 2018 00:26:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1545261997; bh=MmVskWbwqEZ7wnnuljcwcVdo7LFrDR4SgUq72IELnGo=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=WdiiS3phyi3Nj137aLyHhzgqNRDa9nD3++ad9HnZG99j91WZ5Bz0bYe6moOjs3KyD DbgI3Yso7dJyXdio/mHuMBfF/9lX3w+L6Q54576DOzNYDkdPFl58WYNp/lNQCeWvlq pKW+ZwgHwQ/8T84YFigjYmQJLkSVZ1HABzhcm0jPlvfL58F04iyghZDR1vJoqm4Xva jWZG+QCU23mcWcckhbMChfUX9Q4AsvJJvLOGrOpdtLV1hPCC8tFSVIHJqbdlXorQh4 rIeJoPDHGx8YkoI4G5ecaxVIePEmp0sm7qsYOM4EKPNeR56J3OLcMCjesIVIp7LQsH FlbNrC41g/Lqg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.100.2 at mail Date: Thu, 20 Dec 2018 00:28:04 +0100 Message-Id: <5a08ab7483620b2aaf85b55ae9ba45800ade9e81.1545261970.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 2/2] procfs: lseek(/proc/PID/comm, 0, SEEK_END) MIME-Version: 1.0 To: linux-fsdevel@vger.kernel.org Cc: Alexey Dobriyan , Andrew Morton , David Rientjes Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement lseek(fd, 0, SEEK_END) for /proc/PID/comm to return max task name length. This will allow eg. pthread_getname_np() to be able to return ERANGE without modifying thread's name. Signed-off-by: Michał Mirosław --- fs/proc/base.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 3a3b566443e5..80f5911f2ea9 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1575,11 +1575,20 @@ static int comm_open(struct inode *inode, struct file *filp) return single_open(filp, comm_show, inode); } +static loff_t comm_lseek(struct file *file, loff_t offset, int whence) +{ + /* SEEK_END for seq_files normally gets -EINVAL */ + if (whence == SEEK_END && offset == 0) + return TASK_COMM_LEN - 1; + + return seq_lseek(file, offset, whence); +} + static const struct file_operations proc_pid_set_comm_operations = { .open = comm_open, .read = seq_read, .write = comm_write, - .llseek = seq_lseek, + .llseek = comm_lseek, .release = single_release, };