From patchwork Fri Jan 7 23:47:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 530668 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12939C433F5 for ; Fri, 7 Jan 2022 23:47:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231756AbiAGXrE (ORCPT ); Fri, 7 Jan 2022 18:47:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231747AbiAGXrD (ORCPT ); Fri, 7 Jan 2022 18:47:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9CCC061574; Fri, 7 Jan 2022 15:47:02 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 7B9556204A; Fri, 7 Jan 2022 23:47:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4C89C36AED; Fri, 7 Jan 2022 23:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1641599221; bh=BPvTbDVFhiEfy0K1c2fazFFz1nIUVp7PfrgtocUacfE=; h=Date:From:To:Subject:From; b=kk++F41lle4Oy9WYffqZqW3UxCUPcEK/LhxHkN/GTbMpyYtsXRP+4fgurj1QlpSgt ifZr9AaJB4rrQ9vdULTfJBJV74pnzq5udQl+OxGejPT8QwY+Z8QTJMCTR1JV3bkO56 IkoxrVBoJA4LKsLdgnOct0qO3mt4V8PstsZF7oOo= Date: Fri, 07 Jan 2022 15:47:01 -0800 From: akpm@linux-foundation.org To: deller@gmx.de, mm-commits@vger.kernel.org, stable@vger.kernel.org Subject: + usercopy-do-not-fail-on-memory-from-former-init-sections.patch added to -mm tree Message-ID: <20220107234701.4ZAlIDHdY%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch titled Subject: usercopy: do not fail on memory from former init sections has been added to the -mm tree. Its filename is usercopy-do-not-fail-on-memory-from-former-init-sections.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/usercopy-do-not-fail-on-memory-from-former-init-sections.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/usercopy-do-not-fail-on-memory-from-former-init-sections.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Helge Deller Subject: usercopy: do not fail on memory from former init sections On some platforms the memory area between the _stext and the _etext symbols includes the init sections (parisc and csky). If the init sections are freed after bootup, the kernel may reuse this memory. In one test the usercopy checks if the given address is inside the .text section (from _stext to _etext), and it wrongly fails on the mentioned platforms if the memory is from the former init section. Fix this failure by first checking against the init sections before checking against the _stext/_etext section. Link: https://lkml.kernel.org/r/YdeHDDAP+TY5wNeT@ls3530 Fixes: 98400ad75e95 ("parisc: Fix backtrace to always include init funtion names") Signed-off-by: Helge Deller Cc: Signed-off-by: Andrew Morton --- mm/usercopy.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/mm/usercopy.c~usercopy-do-not-fail-on-memory-from-former-init-sections +++ a/mm/usercopy.c @@ -113,6 +113,15 @@ static bool overlaps(const unsigned long return true; } +static bool inside_init_area(const unsigned long ptr, unsigned long n, + char *start, char *end) +{ + unsigned long initlow = (unsigned long) start; + unsigned long inithigh = (unsigned long) end; + + return (ptr >= initlow && (ptr + n) < inithigh); +} + /* Is this address range in the kernel text area? */ static inline void check_kernel_text_object(const unsigned long ptr, unsigned long n, bool to_user) @@ -121,6 +130,12 @@ static inline void check_kernel_text_obj unsigned long texthigh = (unsigned long)_etext; unsigned long textlow_linear, texthigh_linear; + /* Ok if inside the former init sections */ + if (inside_init_area(ptr, n, __init_begin, __init_end)) + return; + if (inside_init_area(ptr, n, _sinittext, _einittext)) + return; + if (overlaps(ptr, n, textlow, texthigh)) usercopy_abort("kernel text", NULL, to_user, ptr - textlow, n);