From mboxrd@z Thu Jan 1 00:00:00 1970 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 E0974C433EF for ; Tue, 12 Apr 2022 21:22:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D87C6B0072; Tue, 12 Apr 2022 17:22:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 686ED6B0073; Tue, 12 Apr 2022 17:22:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54EF56B0074; Tue, 12 Apr 2022 17:22:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 41A446B0072 for ; Tue, 12 Apr 2022 17:22:43 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 06CAE25109 for ; Tue, 12 Apr 2022 21:22:43 +0000 (UTC) X-FDA: 79349501406.09.693D5A1 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf30.hostedemail.com (Postfix) with ESMTP id 6D86D80005 for ; Tue, 12 Apr 2022 21:22:42 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C2441B82036; Tue, 12 Apr 2022 21:22:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28B34C385A1; Tue, 12 Apr 2022 21:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1649798559; bh=c/Bsdvokirgu31USN90XM/QAQckJDOY6WxAtFbseFUI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=2EH85EKs9Vt8PFzqWMQA4N8GKNtH7P1OK3fhtS36nW2eQYYLTD8+XeW4QV6doYBjc NGmySNJe0BWz0xx9Xl6RdMoCPZBooEkutWGP8AsQi7svaschKGlLPUC7j6FrDmeWtw sWaBk2xckdV9/DUk2+R0d8jABGrU3rF07+sJwp9E= Date: Tue, 12 Apr 2022 14:22:38 -0700 From: Andrew Morton To: lipeifeng@oppo.com Cc: michel@lespinasse.org, hughd@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, 21cnbao@gmail.com, zhangshiming@oppo.com Subject: Re: [PATCH] mm: fix align-error when get_addr in unmapped_area_topdown Message-Id: <20220412142238.93e36cc4095e4e0b362db348@linux-foundation.org> In-Reply-To: <20220412081014.399-1-lipeifeng@oppo.com> References: <20220412081014.399-1-lipeifeng@oppo.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: g5uq1km9gzbj9uqcrdnxpjrt717s8jt1 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=2EH85EKs; spf=pass (imf30.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6D86D80005 X-HE-Tag: 1649798562-615895 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: On Tue, 12 Apr 2022 16:10:14 +0800 lipeifeng@oppo.com wrote: > From: lipeifeng > > when we found a suitable gap_end(> info->high_limit), gap_end > must be set to info->high_limit. And we will get the gap_end > after computing highest gap address at the desired alignment. > > 2096 found: > 2097 if (gap_end > info->high_limit) > 2098 gap_end = info->high_limit; > 2099 > 2100 found_highest: > 2101 gap_end -= info->length; > 2102 gap_end -= (gap_end - info->align_offset) & info->align_mask; > 2103 > 2104 VM_BUG_ON(gap_end < info->low_limit); > 2105 VM_BUG_ON(gap_end < gap_start); > 2106 return gap_end; > > so we must promise: info->high_limit - info->low_limit >= > info->length + info->align_mask. > Or in rare cases(info->high_limit - info->low_limit < > info->length + info->align_mask) we will get the addr in > align-error if found suitable gap_end(> info->high_limit). > Thanks. What are the runtime affects of this bug, and how are you able to trigger it? > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -2009,7 +2009,6 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) > if (length < info->length) > return -ENOMEM; > > - length = info->length; > /* > * Adjust search limits by the desired length. > * See implementation comment at top of unmapped_area(). > @@ -2021,6 +2020,8 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) > > if (info->low_limit > high_limit) > return -ENOMEM; > + > + length = info->length; > low_limit = info->low_limit + length; > > /* Check highest gap, which does not precede any rbtree node */ > -- > 2.7.4