Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp625910pxu; Sun, 22 Nov 2020 22:43:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMC+YAoi1yqkG372JjOVI0pVxDevSTTmNIl5r+bVdG3qvDmk65KdoXhNH9XSW7QKebv2FO X-Received: by 2002:a17:906:e254:: with SMTP id gq20mr43531417ejb.520.1606113792109; Sun, 22 Nov 2020 22:43:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606113792; cv=none; d=google.com; s=arc-20160816; b=KmfMh1+0nTdpnZ4f7AWySVSkm9q2idpZv8cnZIz9n2HEO+SDeShGRh7Lhaq7ygtfBf GdI/SRQTAgvR28hivK/duuwXS5ABfqmov2OkLisYFwqbV5EzvFTK3xBxQH1xnBEKqyQV Ouk8vZ9poFtmCxo2SQnq/MaExOetzo0HgvYIA15GGyLBbzD3T+xkTjutVeKhZosldsDc cPdi72V9Xrwoo1xbXYVyHDkfWGax8XbiqjxqGrhRAJtX0uejNDGYtmGipqrap6yZz/jx J+QfeZ226HO/d3OsnchuwRxeo8ieXHFsTnWtjNbCgS6cOHEQ2WOBgtKO6Q1GaGEcVYCl hLCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=eTbHOG/lM4aKr0AWr8B2k2z/stQR5g/IAgb2Z87efyk=; b=0NOq67zvwCTPmo0nDrShnC5Hac5XB5EOk2YEUwwY1gvYydEZ6yAUYKboYBQur94Mat zxmzlX5mJ/C1/n2ouCUBCHhBD7CgY1liE559Nl0fWiHS4QuEBWq7y0tteZHE7xJvDNo2 gk+IMtzzDBKDvUx/PSweg1jIf/6ZOnbRj8k5ZHWdV+2d7h4wwg1Ux8k9e326i+5t7akR gfV3SNnmLUPU2FtnqhFlUPT0Lq74cDr66k45MXXI8KXE1HCGM0KKgpeB+4fmVXPukWAf sDeTym9qq3DhNg/e7EzeAMC/3L0k7UIMUMuy/0NKPSMxzYR4Qa5eszaFFa/MXyYhY/XB 7XNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t12si8034614edc.181.2020.11.22.22.42.48; Sun, 22 Nov 2020 22:43:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726969AbgKWGin (ORCPT + 99 others); Mon, 23 Nov 2020 01:38:43 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:43808 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726626AbgKWGim (ORCPT ); Mon, 23 Nov 2020 01:38:42 -0500 X-UUID: 4478e254bcb4440ebe8244f9399a7d23-20201123 X-UUID: 4478e254bcb4440ebe8244f9399a7d23-20201123 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1958505899; Mon, 23 Nov 2020 14:38:38 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 14:38:36 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 14:38:35 +0800 From: Miles Chen To: Alexey Dobriyan , Andrew Morton CC: , , , , Miles Chen Subject: [RESEND PATCH v1] proc: use untagged_addr() for pagemap_read addresses Date: Mon, 23 Nov 2020 14:38:35 +0800 Message-ID: <20201123063835.18981-1-miles.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we try to visit the pagemap of a tagged userspace pointer, we find that the start_vaddr is not correct because of the tag. To fix it, we should untag the usespace pointers in pagemap_read(). I tested with 5.10-rc4 and the issue remains. My test code is baed on [1]: A userspace pointer which has been tagged by 0xb4: 0xb400007662f541c8 === userspace program === uint64 OsLayer::VirtualToPhysical(void *vaddr) { uint64 frame, paddr, pfnmask, pagemask; int pagesize = sysconf(_SC_PAGESIZE); off64_t off = ((uintptr_t)vaddr) / pagesize * 8; // off = 0xb400007662f541c8 / pagesize * 8 = 0x5a00003b317aa0 int fd = open(kPagemapPath, O_RDONLY); ... if (lseek64(fd, off, SEEK_SET) != off || read(fd, &frame, 8) != 8) { int err = errno; string errtxt = ErrorString(err); if (fd >= 0) close(fd); return 0; } ... } === kernel fs/proc/task_mmu.c === static ssize_t pagemap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { ... src = *ppos; svpfn = src / PM_ENTRY_BYTES; // svpfn == 0xb400007662f54 start_vaddr = svpfn << PAGE_SHIFT; // start_vaddr == 0xb400007662f54000 end_vaddr = mm->task_size; /* watch out for wraparound */ // svpfn == 0xb400007662f54 // (mm->task_size >> PAGE) == 0x8000000 if (svpfn > mm->task_size >> PAGE_SHIFT) // the condition is true because of the tag 0xb4 start_vaddr = end_vaddr; ret = 0; while (count && (start_vaddr < end_vaddr)) { // we cannot visit correct entry because start_vaddr is set to end_vaddr int len; unsigned long end; ... } ... } [1] https://github.com/stressapptest/stressapptest/blob/master/src/os.cc#L158 Signed-off-by: Miles Chen --- fs/proc/task_mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 217aa2705d5d..e9a70f7ee515 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1599,11 +1599,11 @@ static ssize_t pagemap_read(struct file *file, char __user *buf, src = *ppos; svpfn = src / PM_ENTRY_BYTES; - start_vaddr = svpfn << PAGE_SHIFT; + start_vaddr = untagged_addr(svpfn << PAGE_SHIFT); end_vaddr = mm->task_size; /* watch out for wraparound */ - if (svpfn > mm->task_size >> PAGE_SHIFT) + if (start_vaddr > mm->task_size) start_vaddr = end_vaddr; /* -- 2.18.0