From patchwork Sat Aug 3 07:46:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 13752315 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 52C5AC3DA4A for ; Sat, 3 Aug 2024 07:47:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 616056B007B; Sat, 3 Aug 2024 03:47:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C5D46B0083; Sat, 3 Aug 2024 03:47:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B6686B0085; Sat, 3 Aug 2024 03:47:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2EAAE6B007B for ; Sat, 3 Aug 2024 03:47:06 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 84AF341529 for ; Sat, 3 Aug 2024 07:47:05 +0000 (UTC) X-FDA: 82410153210.05.7F3F653 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf29.hostedemail.com (Postfix) with ESMTP id CF41F120005 for ; Sat, 3 Aug 2024 07:47:03 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=qrniNnDW; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3duCtZggKCCsKHcPKNVdNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--davidgow.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3duCtZggKCCsKHcPKNVdNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--davidgow.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722671158; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=W+8zGdX+0w0z65lZvEos03h3yEnQFMCquba341r2hLM=; b=LXlogABnqlaRC2L3/AgNOz+iK2/WGgNPd8GhRtMADn1UlIOGpJemCyNV6+OFbdM08uc5wg yj/2YX8qhj+G990wTq19dDG8UMz8qlRWQw0uUPPP2+sttHrR96G9X9mZ7QucCZsTmQ8KoG VmjVKTFgpZounba2Fi1CyzHYE2H6Vuc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722671158; a=rsa-sha256; cv=none; b=m76F8kiBr7AhEAeWLoAlIqDSgO01g/HM5M4RsUaWK3m6vESyg0a9X3vvyG3pniC5d0QcfI +ghjX18QsSRBcxjFTwRERVt5bsC+jmiBjCgticEpFtcwN9CM2uSDY35bT4yX9WitpZ+Giq l/VUGs8gL2ECa1Ti6j+xWflPXorGiaA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=qrniNnDW; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3duCtZggKCCsKHcPKNVdNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--davidgow.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3duCtZggKCCsKHcPKNVdNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--davidgow.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6506bfeaf64so169270317b3.1 for ; Sat, 03 Aug 2024 00:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722671223; x=1723276023; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=W+8zGdX+0w0z65lZvEos03h3yEnQFMCquba341r2hLM=; b=qrniNnDWLia03oyKRs6JiIl+aUR1ViyYdUNNeJcaLQ4EbZcNu0F6tm3Bc2biYne0fb 9SAEO/83qq7aP9Th/t6MpFHEuzEhoJbEqpZyd1DqzFhcWezhVB8DDrZba6FqwSKE+r+1 hd89m3luTHnyOXY4PFob92AqQ4pLA9tsmm9zb2xD/N3MrCYcGTyB/psHScHHdsYSbntm pQRitTQPQcIcTMuSqvFCnV8RJqQUpCbtkpFxgmZafIMk/rp+99t3O1fSAVvoYVA5a/wr 9wXj4v6pcGlwZlFE5Y/EF0ClkvYHop5jufkTBAyWDiPMNoqKVlBfu3/Ws+3apjzSFdPV rkJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722671223; x=1723276023; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=W+8zGdX+0w0z65lZvEos03h3yEnQFMCquba341r2hLM=; b=O8nX51LPUmVp6XwtT5j4ILQFcrnFKzxG+CO3XLSxqoikgUUppCOzUzjShQ9VaiOL4z ks9vFpylHOBA13pmuW0D8rhxgQ7tsG3vRlRC5h6qxeWenil/NoS09wGK4h9t+Xf6nOcg JR4cnboOkszD8BDs2xoyqRv2ZAo/O0NikuPVuUlGGbzGnZEZ3cFx571BLcR0ntqpqHwj 3ndf+B/qKuPALMAjaxbZjChMb2507Gy89103wHdAVtnp9zcvSbtzVjnMmoZEe5qWvnf+ eF2+w6GQu+wdHsStdkoLW+3GDKjt3Vo6HAhmYexn4ADfN1yKJBOlz2dY3R9hKVZ5R9fn AbIA== X-Forwarded-Encrypted: i=1; AJvYcCVOyAumOlJPzv0dA2/W8xO7TUb91MqzkVP+mAZon54rpUfoKeTD7XNnJ6bnQ2YfT/nNcN7dfZn7RfIE1VrGTjb1vhw= X-Gm-Message-State: AOJu0YxEdVVS+WocNW4UV9y6bfCe1LIKAUxNwZGcVDgXRTRrnq2x/7JK rntM1tooQF4Rw3wEb35eCdNfzDCqCZMoe7UERgdc92X2dajkz9IUK9vtp1x9Nx6BhDOQrJ9UguI 28Rp0UIsedw== X-Google-Smtp-Source: AGHT+IEFvJMwtbC2qA1hrhSyqEbBOlj9S/WB0A5Ne9EveISmD2Fy+ngxQ6PuxWVSb3UKNzYz23fd8E5vGR776w== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:690c:84:b0:646:3ef4:6ad2 with SMTP id 00721157ae682-68964d49c8bmr3342287b3.9.1722671222680; Sat, 03 Aug 2024 00:47:02 -0700 (PDT) Date: Sat, 3 Aug 2024 15:46:41 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog Message-ID: <20240803074642.1849623-2-davidgow@google.com> Subject: [PATCH] mm: Only enforce minimum stack gap size if it's sensible From: David Gow To: Alexandre Ghiti , Kees Cook , Luis Chamberlain , Russell King , Andrew Morton , Linus Walleij , Mark Rutland Cc: David Gow , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CF41F120005 X-Stat-Signature: qb14575s5wgb1w1k8i1iwzjh16dm3836 X-Rspam-User: X-HE-Tag: 1722671223-442443 X-HE-Meta: U2FsdGVkX1915RuPOcLFpepe95wWcyMz8vZanpifKScCt07Y8mw0/3wRlni6/ExUWJBAtFXLh6CNlKxrHrvuyI+RhLfJTXgc9MbS1zJHlCCmVj4q8mOj1UtGE2uAwkH6VVje0EdQwALHbLCH1adiManycrsRrLnF+HuyoWBivGydeqwwv0XvJ9WFPdIkbzoeatBNVnyit7R1zDraD3iRgn7MS24/dmRuEsXIrbJl4lYYQf+Sy/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qtu9yV6WX63nABODnVmB6X4Mp7OiIliFKrImtjRnlrzkpmhg7ZvG38R66E02lDYCf8aJ5TVGMo0KilmKk46o1SKwMJNKfl2gSCwMMgWn5EwlSITMbQKhRg16cQX92y+5xKO9GBazbFUOX5BfkDPgyaUaDgoS5a+7kxBP8TojXD8TbjmryGL8oA1duQFJjqiTtE8qFRnuQb9nR+i/PENC86bSfJ34F0u+ X-Bogosity: Ham, tests=bogofilter, spamicity=0.008933, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The generic mmap_base code tries to leave a gap between the top of the stack and the mmap base address, but enforces a minimum gap size (MIN_GAP) of 128MB, which is too large on some setups. In particular, on arm tasks without ADDR_LIMIT_32BIT, the STACK_TOP value is less than 128MB, so it's impossible to fit such a gap in. Only enforce this minimum if MIN_GAP < MAX_GAP, as we'd prefer to honour MAX_GAP, which is defined proportionally, so scales better and always leaves us with both _some_ stack space and some room for mmap. This fixes the usercopy KUnit test suite on 32-bit arm, as it doesn't set any personality flags so gets the default (in this case 26-bit) task size. This test can be run with: ./tools/testing/kunit/kunit.py run --arch arm usercopy --make_options LLVM=1 Fixes: dba79c3df4a2 ("arm: use generic mmap top-down layout and brk randomization") Signed-off-by: David Gow Reviewed-by: Kees Cook --- This is one possible fix for an issue with the usercopy_kunit suite (and, indeed, the KUnit user_alloc features) on 32-bit arm. The other options are to: - hack the KUnit allocation to force ADDR_LIMIT_32BIT or ADDR_COMPAT_LAYOUT; or - similarly, use an unlimited stack, which forces the legacy layout behind the scenes; or - adjust MIN_GAP based on either STACK_TOP or architecture. Of them, I made the arbitrary call that this was least hacky, but am happy to go with something else if someone who actually knows what's going on suggests it. (Also, does this issue actually mean some strange legacy binaries have been broken with an rlimit-ed stack for ages? Or am I missing something?) Cheers, -- David --- mm/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/util.c b/mm/util.c index bd283e2132e0..baca6cafc9f1 100644 --- a/mm/util.c +++ b/mm/util.c @@ -463,7 +463,7 @@ static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) if (gap + pad > gap) gap += pad; - if (gap < MIN_GAP) + if (gap < MIN_GAP && MIN_GAP < MAX_GAP) gap = MIN_GAP; else if (gap > MAX_GAP) gap = MAX_GAP;