Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932802Ab1CWOuk (ORCPT ); Wed, 23 Mar 2011 10:50:40 -0400 Received: from mout.perfora.net ([74.208.4.195]:60219 "EHLO mout.perfora.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932438Ab1CWOui (ORCPT ); Wed, 23 Mar 2011 10:50:38 -0400 From: Stephen Wilson To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: Andrew Morton , Alexander Viro , Michel Lespinasse , Andi Kleen , Rik van Riel , KOSAKI Motohiro , Matt Mackall , David Rientjes , Nick Piggin , Andrea Arcangeli , Mel Gorman , Hugh Dickins , x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Stephen Wilson Subject: [PATCH v2 resend 09/12] proc: disable mem_write after exec Date: Wed, 23 Mar 2011 10:43:58 -0400 Message-Id: <1300891441-16280-10-git-send-email-wilsons@start.ca> X-Mailer: git-send-email 1.7.3.5 In-Reply-To: <1300891441-16280-1-git-send-email-wilsons@start.ca> References: <1300891441-16280-1-git-send-email-wilsons@start.ca> X-Provags-ID: V02:K0:sYBGW34gTgzVBZLhbI0Ev9Lhbe8+CdEghamowS/hrk0 laqrxXzrayFio5Y7U+e7T+LJqK4MD6frUAsSrlRqiuSk0XJC9X K1FXkfNNHxjfnVjfxB4c/hi4mzIbtcCC7AmQxiZZZWPaYnBwLQ iKinbZHtHmAT36NyZO2okcnfkaju20H/VzO4vv2C9fGwg0qQDy FCJ/1rUTGbwAoRmygvQdXWVuTQ3PQl7vA34c+epkrg= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1113 Lines: 33 This change makes mem_write() observe the same constraints as mem_read(). This is particularly important for mem_write as an accidental leak of the fd across an exec could result in arbitrary modification of the target process' memory. IOW, /proc/pid/mem is implicitly close-on-exec. Signed-off-by: Stephen Wilson --- fs/proc/base.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index d49c4b5..13c5e8c 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -848,6 +848,10 @@ static ssize_t mem_write(struct file * file, const char __user *buf, if (check_mem_permission(task)) goto out; + copied = -EIO; + if (file->private_data != (void *)((long)current->self_exec_id)) + goto out; + copied = -ENOMEM; page = (char *)__get_free_page(GFP_TEMPORARY); if (!page) -- 1.7.3.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/