From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751516AbdHaTNR (ORCPT ); Thu, 31 Aug 2017 15:13:17 -0400 Received: from 78-11-180-123.static.ip.netia.com.pl ([78.11.180.123]:53478 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750998AbdHaTMx (ORCPT ); Thu, 31 Aug 2017 15:12:53 -0400 Date: Thu, 31 Aug 2017 21:12:51 +0200 Message-Id: <422c2ef1aef220d56db0fce5feb8911c4fe541ea.1504206475.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Subject: [PATCH 1/2] procfs: signal /proc/pid/comm write truncation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To: Andrew Morton , Alexey Dobriyan , Ingo Molnar , Michal Hocko , John Stultz , "Eric W. Biederman" , Al Viro Cc: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 f1e1927ccd48..7238a64751e4 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1492,8 +1492,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); @@ -1507,6 +1513,9 @@ static ssize_t comm_write(struct file *file, const char __user *buf, put_task_struct(p); + if (count > 0) + *offset = count; + return count; } -- 2.11.0