From patchwork Thu Nov 14 15:34:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshvardhan Jha X-Patchwork-Id: 13875276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AA44D68B31 for ; Thu, 14 Nov 2024 15:34:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 067E96B00BA; Thu, 14 Nov 2024 10:34:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F31996B00BB; Thu, 14 Nov 2024 10:34:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D35AD6B00BC; Thu, 14 Nov 2024 10:34:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A336A6B00BB for ; Thu, 14 Nov 2024 10:34:54 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E638E161176 for ; Thu, 14 Nov 2024 15:34:53 +0000 (UTC) X-FDA: 82785097542.18.0ACBB7A Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf30.hostedemail.com (Postfix) with ESMTP id 2FADF8001D for ; Thu, 14 Nov 2024 15:33:27 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=nHum0Kac; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf30.hostedemail.com: domain of harshvardhan.j.jha@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=harshvardhan.j.jha@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731598428; a=rsa-sha256; cv=none; b=vd6I90Rfx7O2LHI4s4kv7mYWe4dtCcAsylOd1KR/sOnue8cjNpMh5FvoG0pAviYAmTFy/W 5bvXmO1nHxmgSC5YfDEACXbLV7Zsv6snjw7JLeUYPQa8tBJdaY6vQvJ4KJKeRrcfjQPj8l pB18+Ti8SCPXv09G8okIIrCXnqN0nTQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=nHum0Kac; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf30.hostedemail.com: domain of harshvardhan.j.jha@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=harshvardhan.j.jha@oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731598428; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8v1x2+4ddDfh1GMkn1TAGJMq/5kFEFBLNeiRdPRDjZg=; b=PRHMG/ki0+CUpXP7yjEDPLWeLn0i6HUnDdZ7apM421W/bfX8JVSYQMLG+wpgawdC0DCdRt slvAz6J8+r66hI5lTIIpDoFwDlGEMznLoy7nErNKxX5yzYQv9ONNjwhgzb8B5FbTBazCaw 1eY3YiBg2uP80kffqeeM/U7f/KmOorQ= Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AECcora002606; Thu, 14 Nov 2024 15:34:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=8v1x2 +4ddDfh1GMkn1TAGJMq/5kFEFBLNeiRdPRDjZg=; b=nHum0KacnCCZiEeTvvqkH ovnZz68Y4HuyXJ5ixU6Ct7aSg9Z3uhhPQWuT6aZktxTbhduekB/O8QD+q1qs5E8N GdgYgv2V4vhzIJplJNiTtioJIEQ9b7eEhnL6z46LCCQKzi3oAIJ6/oI/RvqBEwbM t9xfXDUPdPs7s5+D3iQGwO99RIdsSuZ2LHjxGnrp1lpdoH8hoVrMfwU/U/d0cEqh DPtXkPgZbMSPZuHHJ/6rjA11EX8lKb5SbIRr6c5eZAjHT4eXtW08Gw/6ZdICuVSQ 9axBObr/+8lbtGNGL0hU2+PX0az9pQ657etT0GOrcUMHdKzb11PvRVWe/BEs5dOe Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42vsp4k6j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Nov 2024 15:34:50 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 4AEF5cDt001160; Thu, 14 Nov 2024 15:34:49 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42sx6bb02j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Nov 2024 15:34:49 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 4AEFXvi1031217; Thu, 14 Nov 2024 15:34:48 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 42sx6baywk-4; Thu, 14 Nov 2024 15:34:48 +0000 From: Harshvardhan Jha To: akpm@linux-foundation.org Cc: harshvardhan.j.jha@oracle.com, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH 5.4.y 3/4] mm/memory.c: make remap_pfn_range() reject unaligned addr Date: Thu, 14 Nov 2024 07:34:42 -0800 Message-ID: <20241114153443.505015-4-harshvardhan.j.jha@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241114153443.505015-1-harshvardhan.j.jha@oracle.com> References: <20241114153443.505015-1-harshvardhan.j.jha@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-14_05,2024-11-13_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 phishscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2411140121 X-Proofpoint-ORIG-GUID: eS710v4UxfqsDdeqcRLPG8z8qBpv282W X-Proofpoint-GUID: eS710v4UxfqsDdeqcRLPG8z8qBpv282W X-Rspam-User: X-Rspamd-Queue-Id: 2FADF8001D X-Rspamd-Server: rspam01 X-Stat-Signature: xjq7sfxqp4tpgbcrauw6z3a1bn5i5oco X-HE-Tag: 1731598407-18289 X-HE-Meta: U2FsdGVkX1+TYtmQ7f3d5v/3RLKNs5bQmNo1dg3vk0YhLdPd2CkqjEAKHKIT/zhoFgnzhvCODu6D0cNbYSJYHUpDZbdQdTZkBK2JxV7w4R912X6CS3cnX588XRSP5LMOMIAtEYF0GyV9FJ8aaMLnQdgX6Xqk/CPfVDk0m5Z3dIltI56S7r0x1pQJLZOdAreqqdN20PXg8AFwKzwXtQ7X/h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PcKgmibvbipxJdfteq7cazuI8sOgzN+m26e+cRC2k4rGYWw6HwD/clrBwGGytoa70uBzCVI1CeWtlYiah2ObUKB0UNhKU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Alex Zhang commit 0c4123e3fb82d6014d0a70b52eb38153f658541c upstream This function implicitly assumes that the addr passed in is page aligned. A non page aligned addr could ultimately cause a kernel bug in remap_pte_range as the exit condition in the logic loop may never be satisfied. This patch documents the need for the requirement, as well as explicitly adds a check for it. Signed-off-by: Alex Zhang Signed-off-by: Andrew Morton Reviewed-by: Andrew Morton Link: http://lkml.kernel.org/r/20200617233512.177519-1-zhangalex@google.com Signed-off-by: Linus Torvalds (cherry picked from commit 0c4123e3fb82d6014d0a70b52eb38153f658541c) Signed-off-by: Harshvardhan Jha --- mm/memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 50503743724cc..1d009d3d87b34 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1920,7 +1920,7 @@ static inline int remap_p4d_range(struct mm_struct *mm, pgd_t *pgd, /** * remap_pfn_range - remap kernel memory to userspace * @vma: user vma to map to - * @addr: target user address to start at + * @addr: target page aligned user address to start at * @pfn: page frame number of kernel physical memory address * @size: size of mapping area * @prot: page protection flags for this mapping @@ -1939,6 +1939,9 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr, unsigned long remap_pfn = pfn; int err; + if (WARN_ON_ONCE(!PAGE_ALIGNED(addr))) + return -EINVAL; + /* * Physically remapped pages are special. Tell the * rest of the world about it: