Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1260314ybl; Mon, 2 Dec 2019 00:16:54 -0800 (PST) X-Google-Smtp-Source: APXvYqyF1hd6jtWLzl5rNgFxPzp3GYkn1eO5wbTMaTt0tkMUHgS2kCJkQfWLHa2CvOREc8ZRjcKZ X-Received: by 2002:aa7:cf19:: with SMTP id a25mr55759575edy.237.1575274614119; Mon, 02 Dec 2019 00:16:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575274614; cv=none; d=google.com; s=arc-20160816; b=wEvq3wZ/mD2nm4SCAb3ZvY7YEKTVAQe6EEtYe574uVX7WWI9VYKpgYfJp58bD1u1si BB38jWnaklgVSzn3OrLm7VUmuqoD2iRqGn5JOekC1+cRNfGoyfxaCX7tnzqHLLInAJ17 +z4LGHTuoj0NnOuKl2bcyv8DS06k7H/kfDi0rTfGF3ojML1sDQPSt8lCqIU80lgxpRO+ UrOTnQaU12aZXMmspGTjJ8gxYwFEBcWpY5CkFD/tFX5ejVGgMcl/v5dp5QYHHBBaS0Z5 2MlT2SMvDJqvw9k/VETrtXqx0h8GaaS3IY/hU5ZRM74ZhRR1Riut0tBoG4mWHmtgmlxY /Lcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=z0bYMLgDwjlihSEJ0DFI7fP4Wo5PIOr1AsR3umHDI1Y=; b=k2om9Ushjo/TICt0F4gZ+bJtwcKhSRUUyLxDWrgOtlM09d2TXCRLxo1IsnCAfSZzCZ PgQXgjdR8mT/R8RGNnQfLe7rHOeC75etnGOyh6aqeLM3nMTUM8a5Q1nwWg2ubkonqKk7 cNzKpIpAtyGkRTnZFune2x/WLPtMHBUTJlHroqfuQ4lKlLRJaKUMndqcVNs/HQmbrMg9 5GAolsFIV+0JOr/ncm2aqUQFRxQAYb0EhhTQH7JpdfaR6AB9nzVJbUxrB6LfPscTc65P Hdido6qd1kMydOHj/1wavjabpT3H29eIp5HZebeyq1DLlkGFgIf3nHvR2Efw6iMjdTgi JBBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d18si12011065edr.167.2019.12.02.00.16.30; Mon, 02 Dec 2019 00:16:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727442AbfLBIOq (ORCPT + 99 others); Mon, 2 Dec 2019 03:14:46 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:37334 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726030AbfLBIOY (ORCPT ); Mon, 2 Dec 2019 03:14:24 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A2D0261252F11F487C83; Mon, 2 Dec 2019 16:14:17 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Mon, 2 Dec 2019 16:14:11 +0800 From: "zhangyi (F)" To: CC: , , , , , , , , , , , Subject: [PATCH 4.4 4/7] fs/proc: Stop reporting eip and esp in /proc/PID/stat Date: Mon, 2 Dec 2019 16:35:16 +0800 Message-ID: <20191202083519.23138-5-yi.zhang@huawei.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20191202083519.23138-1-yi.zhang@huawei.com> References: <20191202083519.23138-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Lutomirski commit 0a1eb2d474edfe75466be6b4677ad84e5e8ca3f5 upstream. Reporting these fields on a non-current task is dangerous. If the task is in any state other than normal kernel code, they may contain garbage or even kernel addresses on some architectures. (x86_64 used to do this. I bet lots of architectures still do.) With CONFIG_THREAD_INFO_IN_TASK=y, it can OOPS, too. As far as I know, there are no use programs that make any material use of these fields, so just get rid of them. Reported-by: Jann Horn Signed-off-by: Andy Lutomirski Acked-by: Thomas Gleixner Cc: Al Viro Cc: Andrew Morton Cc: Borislav Petkov Cc: Brian Gerst Cc: Kees Cook Cc: Linus Torvalds Cc: Linux API Cc: Peter Zijlstra Cc: Tetsuo Handa Cc: Tycho Andersen Link: http://lkml.kernel.org/r/a5fed4c3f4e33ed25d4bb03567e329bc5a712bcc.1475257877.git.luto@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: zhangyi (F) --- fs/proc/array.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index 60cbaa821164..618c83f1866d 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -425,10 +425,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, mm = get_task_mm(task); if (mm) { vsize = task_vsize(mm); - if (permitted) { - eip = KSTK_EIP(task); - esp = KSTK_ESP(task); - } + /* + * esp and eip are intentionally zeroed out. There is no + * non-racy way to read them without freezing the task. + * Programs that need reliable values can use ptrace(2). + */ } get_task_comm(tcomm, task); -- 2.17.2