Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp205078pxm; Tue, 22 Feb 2022 09:00:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3InF6C2m82QUmxIiHf+vcjfrNfOdZz/r2cbK5OrVNS8kc8mVPrS02kTmjSf58KrZx6/sj X-Received: by 2002:a17:906:e13:b0:6ce:21ca:1b91 with SMTP id l19-20020a1709060e1300b006ce21ca1b91mr20575901eji.193.1645549222433; Tue, 22 Feb 2022 09:00:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645549222; cv=none; d=google.com; s=arc-20160816; b=UTPj9ij/gCsqDbUVeX9lUqmMJbSMedTH/CSaEHaKLgzPgml2KldfQiGlYyTPW29VTq CGtGAhPYIo/pEeCgmcSTwmzBodHogkFBh+8+OWMga3vgszQD8+JXRsq/22l5iZYaq6t0 ifHJ9yZ8PgPGngj476Or2G/JsOI0sGK7DnOdNtelDsFI6rQ8noQY+UUwJ0haShuQOr8o X8emD4TfCpitGpYUT1KoSoZloAdrrh0+3xhyefjRhDa69RzipwS44b96+9SNV+uhknQM t2wlfj4VvHUjNXoIvJWNcIB0gjQN7qB1kxMS/gqjlkqmcQsB1cbZEjX0hBXurI5J45IE K7IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=PQ4rL1/QOmM04Qw6AZ6Im9zhUOuzw/OZ9bnDhTMNsJc=; b=r16UmZdfjNhytiMVTwE6tFpkAKVtZuta+HezJRblb2u4ycDbn7+Iiv5RpLVuNFdjz8 hP89AJFbOXZ1+4OQPJ6K2KJRyzaoZ6HK8JvBjngGQIm5b+a+hHBsYhzqJ/dVv0ZwOEh6 8SUMpPG00iXaVh1TaPWyUQHfDEZSBcVQ27BKMSpHzciYiInLYR/+nNkSau/drEfI1aat I43TLu5zXgdQXro7d/UgXz7Ke/dvH0DWIfei5tArzSVAg4BIXMm+rwD1nFXDs/FucKRS fiyLJ1CoUiozjCO9uIsbpcxLOkMQPkHJmEhf7DbvAF369rR5AtbT+XNTUuJcWMuW++IS /YUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15si12972522edr.56.2022.02.22.08.59.53; Tue, 22 Feb 2022 09:00:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233850AbiBVPyf (ORCPT + 99 others); Tue, 22 Feb 2022 10:54:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233826AbiBVPyc (ORCPT ); Tue, 22 Feb 2022 10:54:32 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBD7E652DC; Tue, 22 Feb 2022 07:53:52 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 87FA21F39E; Tue, 22 Feb 2022 15:53:51 +0000 (UTC) Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 73181A3B88; Tue, 22 Feb 2022 15:53:51 +0000 (UTC) From: Thomas Bogendoerfer To: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Cc: arnd@kernel.org Subject: [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address Date: Tue, 22 Feb 2022 16:53:44 +0100 Message-Id: <20220222155345.138861-1-tsbogend@alpha.franken.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Address errors have always been treated as unaliged accesses and handled as such. But address errors are also issued for illegal accesses like user to kernel space or accesses outside of implemented spaces. This change implements Linux exception handling for accesses to the illegal space above the CPU implemented maximum virtual user address and the MIPS 64bit architecture maximum. With this we can now use a fixed value for the maximum task size on every MIPS CPU and get a more optimized access_ok(). Signed-off-by: Thomas Bogendoerfer --- arch/mips/kernel/unaligned.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/mips/kernel/unaligned.c b/arch/mips/kernel/unaligned.c index df4b708c04a9..7b5aba5df02e 100644 --- a/arch/mips/kernel/unaligned.c +++ b/arch/mips/kernel/unaligned.c @@ -1480,6 +1480,23 @@ asmlinkage void do_ade(struct pt_regs *regs) prev_state = exception_enter(); perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, regs->cp0_badvaddr); + +#ifdef CONFIG_64BIT + /* + * check, if we are hitting space between CPU implemented maximum + * virtual user address and 64bit maximum virtual user address + * and do exception handling to get EFAULTs for get_user/put_user + */ + if ((regs->cp0_badvaddr >= (1UL << cpu_vmbits)) && + (regs->cp0_badvaddr < XKSSEG)) { + if (fixup_exception(regs)) { + current->thread.cp0_baduaddr = regs->cp0_badvaddr; + return; + } + goto sigbus; + } +#endif + /* * Did we catch a fault trying to load an instruction? */ -- 2.29.2