Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp419633pxu; Thu, 3 Dec 2020 03:45:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpnLWTmFVOgLtn4XtSOcZUxjh15lyUph9ENYEiUAj3s51WiiJy7sUrv8JkTJbk8bAgVib1 X-Received: by 2002:a50:fa9a:: with SMTP id w26mr2513894edr.299.1606995958405; Thu, 03 Dec 2020 03:45:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606995958; cv=none; d=google.com; s=arc-20160816; b=O04QT2UGjxqz0mmkaKlGggZcxXP6rU/swKbiDYZI0q3Tei5QEJPj4pnUA7MEHgdNUx +db7LJ/liVl0OC3mP/LzWPd37WvX74ki5fazxfMibX/qe2hGUQ9LbLhKqSp0VKYTA7xP rBHtDV31JMVVuHfphkoq7cgnwUlrB/69wrvtx7JfuD/vIkfJ8vEds4WCFoonXGtGsTJe SnLDe9ExtQCcLzYoUdj3XbMov3walkaeI/bfrb8spf+x+4UMhxvVhi1n8eh25t5SAPR7 CC1Pf1VdEfCm0alwOiKmxCCWNe82HJGEae6vPAootD1/3nOvVYol2spFJegoJC3H+bZU WE9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=06rrsmcea4fcQ+risWK3KyV+itdklxtq34A/gvLW31g=; b=vwBz+SxrIEaJRwSvyccbaThNzynMKFDPf/vtZgJu4m2W4CKQ6RP58Mzk/7Xo0qkYkA oTX8DcPyi4jKePAsK5xJeelduuoR/Xs9zSaijcH0RGAjkqNrvgM3COUrUDkzXKvR3c3c j+7ADs53vJ0JAx9zWwo9yOQcvu0X4kjAgE+43HJWfZfNt5XfE/KMThQd/TvDYX/yC7K5 eTISRv2KmGqXDbrLrdvmfLph/s9CYBUtFySAudefgWU4/NWwFOgDML1m2E282H6jkgWg 5lxixhvNPRGGBIwc+1mK+sjvBv0O4vB3YBT9wDVPrqiyspd9iJ2eK4oUQKhWw7ZsonlP 1Tlg== 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=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yj16si1039839ejb.693.2020.12.03.03.45.35; Thu, 03 Dec 2020 03:45:58 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730214AbgLCLna (ORCPT + 99 others); Thu, 3 Dec 2020 06:43:30 -0500 Received: from foss.arm.com ([217.140.110.172]:37972 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726710AbgLCLna (ORCPT ); Thu, 3 Dec 2020 06:43:30 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1D325113E; Thu, 3 Dec 2020 03:42:44 -0800 (PST) Received: from [10.37.8.53] (unknown [10.37.8.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4CC8E3F66B; Thu, 3 Dec 2020 03:42:40 -0800 (PST) Subject: Re: [PATCH v2] proc: use untagged_addr() for pagemap_read addresses To: Miles Chen , Alexey Dobriyan , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com, Andrey Konovalov , Alexander Potapenko , Andrey Ryabinin , Catalin Marinas , Dmitry Vyukov , Marco Elver , Will Deacon , "Eric W . Biederman" , Song Bao Hua , stable@vger.kernel.org References: <20201127050738.14440-1-miles.chen@mediatek.com> From: Vincenzo Frascino Message-ID: Date: Thu, 3 Dec 2020 11:45:56 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201127050738.14440-1-miles.chen@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Miles, On 11/27/20 5:07 AM, Miles Chen wrote: > 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(). > Nit: s/usespace/userspace/ (please search and replace all occurrences :) ) > I tested with 5.10-rc4 and the issue remains. > > Explaination from Catalin in [1]: > Nit: s/Explaination/Explanation/ (please search and replace all occurrences :) ) > " > Arguably, that's a user-space bug since tagged file offsets were never > supported. In this case it's not even a tag at bit 56 as per the arm64 > tagged address ABI but rather down to bit 47. You could say that the > problem is caused by the C library (malloc()) or whoever created the > tagged vaddr and passed it to this function. It's not a kernel > regression as we've never supported it. > > Now, pagemap is a special case where the offset is usually not generated > as a classic file offset but rather derived by shifting a user virtual > address. I guess we can make a concession for pagemap (only) and allow > such offset with the tag at bit (56 - PAGE_SHIFT + 3). > " > > My test code is baed on [2]: Nit: s/baed/based/ (please search and replace all occurrences :) ) [...] > --- > fs/proc/task_mmu.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index 217aa2705d5d..92b277388f05 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -1599,11 +1599,15 @@ static ssize_t pagemap_read(struct file *file, char __user *buf, > > src = *ppos; > svpfn = src / PM_ENTRY_BYTES; > - start_vaddr = svpfn << PAGE_SHIFT; > end_vaddr = mm->task_size; > > /* watch out for wraparound */ > - if (svpfn > mm->task_size >> PAGE_SHIFT) > + start_vaddr = end_vaddr; > + if (svpfn < (ULONG_MAX >> PAGE_SHIFT)) It seems that 'svpfn' should be less-then-equal (<=) '(ULONG_MAX >> PAGE_SHIFT)'. Is there any specific reason why this is not the case? > + start_vaddr = untagged_addr(svpfn << PAGE_SHIFT); > + > + /* Ensure the address is inside the task */ > + if (start_vaddr > mm->task_size) > start_vaddr = end_vaddr; > > /* > Otherwise: Reviewed-by: Vincenzo Frascino -- Regards, Vincenzo