From patchwork Mon Oct 11 14:31:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongwei Song X-Patchwork-Id: 12550127 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F09CC433EF for ; Mon, 11 Oct 2021 14:34:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AAD5E6023F for ; Mon, 11 Oct 2021 14:34:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AAD5E6023F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=me.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 50A2180007; Mon, 11 Oct 2021 10:34:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E07E6B0072; Mon, 11 Oct 2021 10:34:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A7A380007; Mon, 11 Oct 2021 10:34:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id 2D12F6B0071 for ; Mon, 11 Oct 2021 10:34:07 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CBEFA23E4D for ; Mon, 11 Oct 2021 14:34:06 +0000 (UTC) X-FDA: 78684401292.04.6A2880A Received: from pv50p00im-ztdg10021201.me.com (pv50p00im-ztdg10021201.me.com [17.58.6.45]) by imf04.hostedemail.com (Postfix) with ESMTP id 6D4F150019B6 for ; Mon, 11 Oct 2021 14:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1633962845; bh=JRB2I0DdtVVtDX+M6k5hW9hyckKkPozCFhvu4peWiT8=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=VMxjjtqCM5srj67fJKgnJyWGKg27FMpkMeOLKe4kY37aHDbmRB2ngM1+AOoUMMKbI twQM9stdCuNtEblaSRuC6WaBFelH55ItmSNls8wtqMwKAWXv1cAo8e5Xuu84lIwlRm 35lJ3IzmLoDkg2b6mAgHSgPdDgXZSagDc4GnSp63Qj0Yl6UaxOqxdAd2qZoZhu0y1b GykPUbsXEHU5LmPkgyK8w3PyE5kalUF8dsX6ynuBzkK/ni4D1hJGLkuYlBd0A3CQ6T sx5villyGhAdo97VtdUtPtwYzrQpkjN+t1J5HVdeqVqpSpnFQs23sfN/Sl55V+BrLP AT4GG98aivFjw== Received: from xiongwei.. (unknown [120.245.2.114]) by pv50p00im-ztdg10021201.me.com (Postfix) with ESMTPSA id B1049A405D9; Mon, 11 Oct 2021 14:33:56 +0000 (UTC) From: sxwjean@me.com To: linux-mm@kvack.org, x86@kernel.org Cc: Xiongwei Song , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Kees Cook , "H. Peter Anvin" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Arnd Bergmann , Al Viro , Gabriel Krisman Bertazi , Lai Jiangshan , Huang Rui , Yazen Ghannam , Kim Phillips , Oleg Nesterov , Balbir Singh , "David S. Miller" , sxwjean@me.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] mm/util: Allow to pass a specific task size when getting mmapping base Date: Mon, 11 Oct 2021 22:31:46 +0800 Message-Id: <20211011143150.318239-3-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211011143150.318239-1-sxwjean@me.com> References: <20211011143150.318239-1-sxwjean@me.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.790 definitions=2021-10-11_05:2021-10-07,2021-10-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=715 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2009150000 definitions=main-2110110085 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6D4F150019B6 X-Stat-Signature: cg8mw8giqsitk3ysba5mgmr4er77oswq Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=me.com header.s=1a1hai header.b=VMxjjtqC; dmarc=pass (policy=quarantine) header.from=me.com; spf=pass (imf04.hostedemail.com: domain of sxwjean@me.com designates 17.58.6.45 as permitted sender) smtp.mailfrom=sxwjean@me.com X-HE-Tag: 1633962846-829196 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: From: Xiongwei Song In x86, a 64bit task may invoke a 32 bit syscall, which is in compat syscall. Then we have to provide 32bit mapping base. Signed-off-by: Xiongwei Song --- mm/util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/util.c b/mm/util.c index 40b1a8837c0b..38326ef21a3b 100644 --- a/mm/util.c +++ b/mm/util.c @@ -385,14 +385,15 @@ static int mmap_is_legacy(struct rlimit *rlim_stack) #define MIN_GAP (SZ_128M) #define MAX_GAP (STACK_TOP / 6 * 5) -static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) +static unsigned long mmap_base(unsigned long rnd, unsigned long task_size, + struct rlimit *rlim_stack) { unsigned long gap = rlim_stack->rlim_cur; unsigned long pad = stack_guard_gap; /* Account for stack randomization if necessary */ if (current->flags & PF_RANDOMIZE) - pad += (STACK_RND_MASK << PAGE_SHIFT); + pad += (in_compat_syscall() ? 0x7ff : STACK_RND_MASK) << PAGE_SHIFT; /* Values close to RLIM_INFINITY can overflow. */ if (gap + pad > gap) @@ -403,7 +404,7 @@ static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) else if (gap > MAX_GAP) gap = MAX_GAP; - return PAGE_ALIGN(STACK_TOP - gap - rnd); + return PAGE_ALIGN(task_size - gap - rnd); } void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) @@ -418,7 +419,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) mm->mmap_base = mm->mmap_legacy_base; mm->get_unmapped_area = arch_get_unmapped_area; } else { - mm->mmap_base = mmap_base(random_factor, rlim_stack); + mm->mmap_base = mmap_base(random_factor, STACK_TOP, rlim_stack); mm->get_unmapped_area = arch_get_unmapped_area_topdown; } }