Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2610193pxb; Tue, 13 Apr 2021 06:12:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL7fx8v+82DkHNnzJ5HyE6V/glXssOS8nYwaZb4padNr/Uf5QXMB2bMCSLqOKAM0saYQwl X-Received: by 2002:a05:6a00:796:b029:247:7a27:d612 with SMTP id g22-20020a056a000796b02902477a27d612mr19075434pfu.78.1618319521034; Tue, 13 Apr 2021 06:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618319521; cv=none; d=google.com; s=arc-20160816; b=DmV8nPhuXuU8c28D3FG/H0gQf1WdRffkyc3v7FQHeDZ6Z+rVJ3Jp89aT7BH2ARi4u+ LQPIKkI6jjjYBqDNHxbRrp7eVIWs5iKfyyg788jV6MN8O64Ij7A19HShRN5PPpwe9G7x 4mzUX27iYeWEwFNrTBym9HRD+bhTyMdMtl+AT0afD+ZnFe7XihYFUb7jOtIq65AIjtAX 6AgetwpFG07wSHjHp3moEAXJLUeBFzb+kYXodEw9J4xeoK53wuAv4lfoKlqZoqgmpDav m71Z7bjAgSa5j7zoKNE5s1MxlJxEG/9QNbDUbqkB3muacD+Yqb+gTBKny5+2dtPe1/ZK GnfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=uuaAYSangUt1vj2Tx+x76aWAYZKEWCMdQtpt/Jhl7HM=; b=XVXuRLSSr/TNJgSg98jovFf6vBw4uzZMpXhJFXJVhzBsUAr6jdVq3nOhGJZD/Zb6+y UY9RGjTA8YwKNcWliP2SST2AAiaiXBKl8Bb+ifzF2OsPG3AMQysrok8pB2KT9P1DiLam L68IdjFzpZH7Ie8lIfGqZwtylw1SEGSUU2my+Kkz+8UDsw+dVPt0ioUBwbnuinM2DgZ4 Q/21+pHFPHWffNvsq1qmAaIKuX2kBPoHGzNc9IBUV+rKeH0KxAKFkqPxWVl5UduuM5OY VNDxexhcBEN5VBvyRO9QQx66bHrTCkSY3xv+oaVoEdSbAxHFholgYXO1+GQGmYiToRfJ wAbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z191si18747910pgz.158.2021.04.13.06.11.48; Tue, 13 Apr 2021 06:12:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241977AbhDMC57 (ORCPT + 99 others); Mon, 12 Apr 2021 22:57:59 -0400 Received: from mail.loongson.cn ([114.242.206.163]:33852 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237380AbhDMC57 (ORCPT ); Mon, 12 Apr 2021 22:57:59 -0400 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx78ucCHVgX2IHAA--.14150S2; Tue, 13 Apr 2021 10:57:33 +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] module: Use ARG_MAX as second argument of strndup_user() in load_module() Date: Tue, 13 Apr 2021 10:57:31 +0800 Message-Id: <1618282651-14507-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dx78ucCHVgX2IHAA--.14150S2 X-Coremail-Antispam: 1UD129KBjvJXoWxuF15GFWrZFy3Wr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ailing-List: linux-kernel@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: diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h index 9e9e3aa..f4fb8ca 100644 --- a/arch/mips/include/asm/uaccess.h +++ b/arch/mips/include/asm/uaccess.h @@ -612,8 +612,8 @@ static inline long strnlen_user(const char __user *s, long n) { long res; - if (!access_ok(s, n)) - return -0; + if (!access_ok(s, 1)) + return 0; might_fault(); __asm__ __volatile__( 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 --- 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; -- 2.1.0