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; }