From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751407AbdAMJ1o (ORCPT ); Fri, 13 Jan 2017 04:27:44 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:21712 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751322AbdAMJ1e (ORCPT ); Fri, 13 Jan 2017 04:27:34 -0500 From: Xie XiuQi To: , CC: , Subject: [PATCH] module: fix failed to rmmod kernel module when it's name is too long Date: Fri, 13 Jan 2017 17:19:03 +0800 Message-ID: <1484299143-157054-1-git-send-email-xiexiuqi@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.58789C08.00DF,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 86d15dd3be74c7e79b19b2b6366cdfb5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the name of kernel module is more than 56 chars (include 56), the module could be insmod successfully, but failed to rmmod. $ strace rmmod tst_1111111111222222222233333333334444444444555555555566 ... open("/sys/module/tst_1111111111222222222233333333334444444444555555555566/initstate", O_RDONLY|O_CLOEXEC) = 3 read(3, "live\n", 31) = 5 read(3, "", 26) = 0 close(3) = 0 openat(AT_FDCWD, "/sys/module/tst_1111111111222222222233333333334444444444555555555566/holders", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3 getdents(3, /* 2 entries */, 32768) = 48 getdents(3, /* 0 entries */, 32768) = 0 close(3) = 0 open("/sys/module/tst_1111111111222222222233333333334444444444555555555566/refcnt", O_RDONLY|O_CLOEXEC) = 3 read(3, "0\n", 31) = 2 read(3, "", 29) = 0 close(3) = 0 delete_module("tst_1111111111222222222233333333334444444444555555555566", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory) write(2, "rmmod: ERROR: could not remove '"..., 117rmmod: ERROR: could not remove 'tst_1111111111222222222233333333334444444444555555555566': No such file or directory ) = 117 write(2, "rmmod: ERROR: could not remove m"..., 122rmmod: ERROR: could not remove module tst_1111111111222222222233333333334444444444555555555566: No such file or directory ) = 122 exit_group(1) = ? +++ exited with 1 +++ In this patch, we just set the last char to '\0', to make sure the name has the tailing '\0'. Reported-by: Zhang Liguang Signed-off-by: Xie XiuQi --- kernel/module.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/module.c b/kernel/module.c index 0e54d5b..3eac266 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2928,6 +2928,7 @@ static struct module *setup_load_info(struct load_info *info, int flags) } /* This is temporary: point mod into copy of data. */ mod = (void *)info->sechdrs[info->index.mod].sh_addr; + mod->name[MODULE_NAME_LEN - 1] = '\0'; if (info->index.sym == 0) { pr_warn("%s: module has no symbols (stripped?)\n", mod->name); -- 1.8.3.1