Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp115983ybz; Wed, 15 Apr 2020 05:37:25 -0700 (PDT) X-Google-Smtp-Source: APiQypLFTu55LutcbUovPF/SDXDiu8BeMo7MrKou58Cr56I0ZDWEhgdfGBGRKeAs8xQrQB1I1mS8 X-Received: by 2002:a05:6402:1657:: with SMTP id s23mr22681397edx.74.1586954245046; Wed, 15 Apr 2020 05:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586954245; cv=none; d=google.com; s=arc-20160816; b=B7AYuK9N6ZNAanypjviZLB8sd62p/crzYacXT4dxl4GdeT95wSk1+2mA8W4FTnr3i7 nvdMAGa0GwdyPX1xX05nnCPPD+BUBI2o78PJSliNnN92TFoSvuzWImRtF5YdAmnytJIZ h97eM+/b8FnpLior/UW4WxwMIOLwLaZv5ycJnOf8upkHC6aXDdaJnIZAnoVXC7QGx5P9 fwhap2gnclFF6X+mJ0c6VoZ0z5F8Fk2az/9KBMFGX/goRwKh1er+EUPY8cEl0JwUqnDB j8vbkv93IyPzwzA/7/idKJDXciDbtUlTG3ufeYQn1LMIw2v8w4/eYFeVjM5uZYfCDysO UUOw== 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=Tr+Zmr/LTldARvTgYR5ogVVH2f/hgJy5hU1N+DHj88E=; b=VAPgALbgdrMkTYm0cKEF8erQ3pQmDB3FwCFzlFbORrNVOKs3KwW2+MgVmE9AqWTZXg 4p7BRimPogh8/DYMYI7wBE4EvIyxx5byUIqxHsHJrJMqStuRnVnyXTywLF/JZ8QzJPDe ktDTG8Pt6wVhGlrmUDdTqSKmU1uGJL1nwBZeAnB5L7Y69HM3qVc5peM43cX8YpAxhxP0 GxMqwAnU1cj3Na2Zxka1X0LRt2E7PnEGbz1D1sYXKSOW4vDc/INyBIXxid1I4GgCnCWJ Py06eSt8BDs+oLVYGlCGFt8BT1vAqa1KPU3DyPeDDNabKEuVdIh1EfsKzN7pJ49UtZRd RNug== 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 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 u3si998311edq.473.2020.04.15.05.36.59; Wed, 15 Apr 2020 05:37:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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: best guess record for 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 S2437275AbgDNPKy (ORCPT + 99 others); Tue, 14 Apr 2020 11:10:54 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37982 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2440279AbgDNPId (ORCPT ); Tue, 14 Apr 2020 11:08:33 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03EF6S1Y035084 for ; Tue, 14 Apr 2020 11:08:32 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0b-001b2d01.pphosted.com with ESMTP id 30ba1htq8y-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 e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 14 Apr 2020 16:07:57 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp01.uk.ibm.com (192.168.101.131) 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 03EF8RTu28377202 (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 F20184C044; Tue, 14 Apr 2020 15:08:26 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AE1594C046; Tue, 14 Apr 2020 15:08:26 +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 1/2] mm/mmap.c: add more sanity checks to get_unmapped_area() Date: Tue, 14 Apr 2020 17:08:22 +0200 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-TM-AS-GCONF: 00 x-cbid: 20041415-4275-0000-0000-000003BFC2F5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20041415-4276-0000-0000-000038D53658 Message-Id: <88d4e091d2905e49f6bed4fd7d98cbab1e9f0fec.1586876678.git.agordeev@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-14_06:2020-04-14,2020-04-14 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=542 suspectscore=1 impostorscore=0 clxscore=1015 spamscore=0 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 Generic get_unmapped_area() function does sanity checks of address and length of the area to be mapped. Yet, it lacks checking against mmap_min_addr and mmap_end limits. At the same time the default implementation of functions arch_get_unmapped_area[_topdown]() and some architecture callbacks do mmap_min_addr and mmap_end checks on its own. Put additional checks into the generic code and do not let architecture callbacks to get away with a possible area outside of the allowed limits. That could also relieve arch_get_unmapped_area[_topdown]() callbacks of own address and length sanity checks. CC: linux-mm@kvack.org Signed-off-by: Alexander Gordeev --- mm/mmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 0681bd5..5b22d47 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2208,12 +2208,13 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) unsigned long (*get_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); + const unsigned long mmap_end = arch_get_mmap_end(addr); unsigned long error = arch_mmap_check(addr, len, flags); if (error) return error; /* Careful about overflows.. */ - if (len > TASK_SIZE) + if (len > mmap_end - mmap_min_addr) return -ENOMEM; get_area = current->mm->get_unmapped_area; @@ -2234,7 +2235,7 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) if (IS_ERR_VALUE(addr)) return addr; - if (addr > TASK_SIZE - len) + if ((addr < mmap_min_addr) || (addr > mmap_end - len)) return -ENOMEM; if (offset_in_page(addr)) return -EINVAL; -- 1.8.3.1