Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp590675ybz; Wed, 15 Apr 2020 14:41:28 -0700 (PDT) X-Google-Smtp-Source: APiQypJiJIAR10QdDafqUl+OJOEdFyN70/mozQhkT+3sjJJhaqprQSEKfe9w28huLJLQ8U6siw6+ X-Received: by 2002:a05:6402:2c8:: with SMTP id b8mr26131260edx.242.1586986888295; Wed, 15 Apr 2020 14:41:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586986888; cv=none; d=google.com; s=arc-20160816; b=Ym7x90dVHn/uxVwnwfn2+HSOH9HXh7CcN14Kb5l0ccrAl0AIuvyPD4nD3BVXLx2T+L CR8wEL06IWBFcm4CJc2Je1VV3WTurDul08JDKlPwaSSwmiLt2fOPp27EbEej5969GAyw G60vfoc0IRwjJcdrwS4poDOBPF6K/H1/EAy4uCdkL5y3rFi7etRk12MN7WDBZo0k1b8d 23s/3HGWBhGRrR0MpZOxJnQJNHYlbPHH8DibQQDXlhwWpttsHz4+KCp3hEQ8Q4h8vHV4 dePEeElETKq+icHa06Poc3Fjiz4fJ6hruyPMbPhcNm4b/O3X+0hFOC0WO/7PRiB/P2di qzpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=E8nFM+wEiZXbZq0emejkFnOXCWdwvV/7dYc5NWUxvMM=; b=qAoYyXGgLuiFYwY8pKuvECtuCYVw2obinDMJr/t4W5MYFrtEHa6Tf9lOLW/UDoobkj nG2DZ4jsNo6KY9LWKMlduBbyjuznlsCMLBvg148F7jN1GVncDGb9E8z+yT5uaqkHhB0w opcn27p2VimFFxZkmYzzzu4eJ89a5yHr9zgCw9vHbNye3jMqyf4zX1Akrpdl0rjH+xeu KqM7gc28PwcKP97LtdZ2eLEWIZ4CRBiW7/Kk6B66lUB0QRVl/3bDioYK/5l5bZtJ9Q29 HcrIpWoXQGpO5JLQjsJ9ONgMXVK80YaqFuiTkNtTM2A/kz2rXjOOiPbRYJuZtv6vbPXi FJqA== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x26si11443017edr.138.2020.04.15.14.41.04; Wed, 15 Apr 2020 14:41:28 -0700 (PDT) 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436993AbgDNPJb (ORCPT + 99 others); Tue, 14 Apr 2020 11:09:31 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:11530 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440280AbgDNPIe (ORCPT ); Tue, 14 Apr 2020 11:08:34 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03EF49XE052373 for ; Tue, 14 Apr 2020 11:08:33 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 30b6sg8av6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 14 Apr 2020 11:08:32 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 14 Apr 2020 16:07:55 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 14 Apr 2020 16:07:54 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 03EF8RnQ54132906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Apr 2020 15:08:27 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5BADC4C040; Tue, 14 Apr 2020 15:08:27 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 149244C046; Tue, 14 Apr 2020 15:08:27 +0000 (GMT) Received: from oc3871087118.ibm.com (unknown [9.145.30.155]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 14 Apr 2020 15:08:26 +0000 (GMT) From: Alexander Gordeev To: linux-kernel@vger.kernel.org Cc: Alexander Gordeev , linux-mm@kvack.org Subject: [PATCH RESEND 2/2] mm/mmap.c: deny fixed mappings outside of allowed limits Date: Tue, 14 Apr 2020 17:08:23 +0200 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-TM-AS-GCONF: 00 x-cbid: 20041415-0016-0000-0000-0000030470C8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20041415-0017-0000-0000-0000336868F9 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-14_07:2020-04-14,2020-04-14 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 bulkscore=0 malwarescore=0 clxscore=1015 mlxscore=0 phishscore=0 adultscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=550 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004140123 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is possible to request a fixed mapping address below mmap_min_addr and succeed. This update adds early checks of mmap_min_addr and mmap_end boundaries and fixes the above issue. CC: linux-mm@kvack.org Signed-off-by: Alexander Gordeev --- mm/mmap.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 5b22d47..9a16e25 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -62,6 +62,14 @@ #define arch_mmap_check(addr, len, flags) (0) #endif +#ifndef arch_get_mmap_end +#define arch_get_mmap_end(addr) (TASK_SIZE) +#endif + +#ifndef arch_get_mmap_base +#define arch_get_mmap_base(addr, base) (base) +#endif + #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS const int mmap_rnd_bits_min = CONFIG_ARCH_MMAP_RND_BITS_MIN; const int mmap_rnd_bits_max = CONFIG_ARCH_MMAP_RND_BITS_MAX; @@ -1369,6 +1377,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, unsigned long pgoff, unsigned long *populate, struct list_head *uf) { + const unsigned long mmap_end = arch_get_mmap_end(addr); struct mm_struct *mm = current->mm; int pkey = 0; @@ -1391,8 +1400,12 @@ unsigned long do_mmap(struct file *file, unsigned long addr, if (flags & MAP_FIXED_NOREPLACE) flags |= MAP_FIXED; - if (!(flags & MAP_FIXED)) + if (flags & MAP_FIXED) { + if ((addr < mmap_min_addr) || (addr > mmap_end)) + return -ENOMEM; + } else { addr = round_hint_to_min(addr); + } /* Careful about overflows.. */ len = PAGE_ALIGN(len); @@ -2089,14 +2102,6 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) return addr; } -#ifndef arch_get_mmap_end -#define arch_get_mmap_end(addr) (TASK_SIZE) -#endif - -#ifndef arch_get_mmap_base -#define arch_get_mmap_base(addr, base) (base) -#endif - /* Get an address range which is currently unmapped. * For shmat() with addr=0. * -- 1.8.3.1