From patchwork Tue Apr 13 03:23:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 12199209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C681C433ED for ; Tue, 13 Apr 2021 03:23:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C7046128A for ; Tue, 13 Apr 2021 03:23:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240812AbhDMDYB (ORCPT ); Mon, 12 Apr 2021 23:24:01 -0400 Received: from mail.loongson.cn ([114.242.206.163]:39876 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237789AbhDMDYA (ORCPT ); Mon, 12 Apr 2021 23:24:00 -0400 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Axnci5DnVgd2QHAA--.9969S2; Tue, 13 Apr 2021 11:23:38 +0800 (CST) From: Tiezhu Yang To: Jessica Yu , Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Xuefeng Li Subject: [PATCH RFC v2] module: Use ARG_MAX as second argument of strndup_user() in load_module() Date: Tue, 13 Apr 2021 11:23:36 +0800 Message-Id: <1618284216-17004-1-git-send-email-yangtiezhu@loongson.cn> X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43ZEXa7VUUivttUUUU U== X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org When update kernel with the latest mips-next, we can not login through a graphical interface, this is because drm radeon GPU driver does not work, we can not see the boot message "[drm] radeon kernel modesetting enabled." through the serial console. drivers/gpu/drm/radeon/radeon_drv.c static int __init radeon_module_init(void) { [...] DRM_INFO("radeon kernel modesetting enabled.\n"); [...] } I use git bisect to find out the commit 04324f44cb69 ("MIPS: Remove get_fs/set_fs") is the first bad commit. I analysis and test the changes in the above first bad commit and then find out the following obvious difference which leads to the login issue. arch/mips/include/asm/uaccess.h static inline long strnlen_user(const char __user *s, long n) { [...] if (!access_ok(s, n)) return -0; [...] } I use dump_stack() to find out the following call trace: load_module() strndup_user() strnlen_user() load_module() failed in the following error path, we can see that the second argument of strndup_user() is very big. static int load_module(struct load_info *info, const char __user *uargs, int flags) { [...] mod->args = strndup_user(uargs, ~0UL >> 1); if (IS_ERR(mod->args)) { err = PTR_ERR(mod->args); goto free_arch_cleanup; } [...] } As discussed earlier [1], it seems that just modify the exception check condition in strnlen_user() to fix load_module() failure, like this: arch/mips/include/asm/uaccess.h static inline long strnlen_user(const char __user *s, long n) { [...] if (!access_ok(s, 1)) return 0; [...] } At the other hand, I search strndup_user() in the kernel tree, the second argument of them are almost a macro or a fixed value which is relatively small, such as PAGE_SIZE, PATH_MAX. So I think maybe we can use ARG_MAX as second argument of strndup_user() in load_module(). With this patch, the load_module() failure disappered and we can login normally through a graphical interface. [1] https://lore.kernel.org/patchwork/patch/1411214/ Signed-off-by: Tiezhu Yang --- v2: Update the commit message to avoid using diff content - patch(1) might not work kernel/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/module.c b/kernel/module.c index 3047935..30d320b 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3998,7 +3998,7 @@ static int load_module(struct load_info *info, const char __user *uargs, flush_module_icache(mod); /* Now copy in args */ - mod->args = strndup_user(uargs, ~0UL >> 1); + mod->args = strndup_user(uargs, ARG_MAX); if (IS_ERR(mod->args)) { err = PTR_ERR(mod->args); goto free_arch_cleanup;