Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp257581pxk; Tue, 1 Sep 2020 23:47:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2B9FZopXjUS0N39hgkaMjpyUwPUSJ4tIeolV1gqbZRcO64AuUtH5QfWzF9/gPst1XThgJ X-Received: by 2002:a17:906:3c47:: with SMTP id i7mr4801829ejg.554.1599029254450; Tue, 01 Sep 2020 23:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599029254; cv=none; d=google.com; s=arc-20160816; b=eTGGN+YArDUz2Eke5GWBpsN7LbVMbrpNLFNUTAY1ppZKCe8PghZTYC9yigQgJ0bGnu 1aqrDdlbLDgfXcDpsYI+Pjdle3DnVsH1VK8yA46N5t2dkeIRep41MIS4DxkHtF+axq1n 13JPEEu+KBolSnY7ekVNdc9BAC5Dj6C5j/8eP5MHDayKE2rSHVLAc/D9oIH9USOHRWXK UXxeB7SB1CYKwsXkzirXBq/3Z4+TIWyb5XCAL+hTMEop16j8grn/TvLaPImcesXcghiM +fVrOpprCHf8baWBPLVglaWjUCYLkveNDowLHnQe/ipb3gug8JuAxENlu+dQCBWWV1uA nDYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=fgPetbAZyWF8LpDx6Ka/+WX49EM4fG1ZexTaoIdAKEA=; b=TOHdg4vGuxJOYJhJTOZVHBKMr6FzuEkS23rBf2+sPFs7ESSe4CFg2W+W9rOcud0+AP jCBNpL6GBxgBHcni+oZED+h4S6x4l4B2+uNHKTmFTcbZFUBXIkJ/1zZ6l1zVY4ku0AWA vjZWmg2BUU1gc2olqULxRAJLkZGv60qQePbUSdfX4V5Ptqz3OmLhEoV96wlTDaOTZ8SB 9Yf5JHbfMNTGxkzawdRrnpWjwRil1G4uxXKEHKZVTNkNCQDYDMfs60CSGt42Iou1lFVN fXBRWBs74wwYV0doToIryogeHgPZKZTw6p6+7gew+rakjwW3D1+G6uKP2Y0RYVsErTF2 deqw== 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 cz6si2238566edb.188.2020.09.01.23.47.03; Tue, 01 Sep 2020 23:47:34 -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 S1726814AbgIBGq1 (ORCPT + 99 others); Wed, 2 Sep 2020 02:46:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:58262 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726247AbgIBGq0 (ORCPT ); Wed, 2 Sep 2020 02:46:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B57E4AC1D; Wed, 2 Sep 2020 06:46:26 +0000 (UTC) From: Qu Wenruo To: linux-kernel@vger.kernel.org Cc: jeyu@suse.de, Lucas De Marchi Subject: [PATCH] module: Add more error message for failed kernel module loading Date: Wed, 2 Sep 2020 14:46:19 +0800 Message-Id: <20200902064619.67343-1-wqu@suse.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When kernel module loading failed, user space only get one of the following error messages: - ENOEXEC This is the most confusing one. From corrupted ELF header to bad WRITE|EXEC flags check introduced by in module_enforce_rwx_sections() all returns this error number. - EPERM This is for blacklisted modules. But mod doesn't do extra explain on this error either. - ENOMEM The only error which needs no explain. This means, if a user got "Exec format error" from modprobe, it provides no meaningful way for the user to debug, and will take extra time communicating to get extra info. So this patch will add extra error messages for -ENOEXEC and -EPERM errors, allowing user to do better debugging and reporting. Signed-off-by: Qu Wenruo Reviewed-by: Lucas De Marchi --- Changelog: v2: - Add extra section description for the error message of module_enforce_rwx_sections() - Add Reviewed-by tags. --- kernel/module.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 1c5cff34d9f2..2c00059ac1c9 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2096,8 +2096,11 @@ static int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, int i; for (i = 0; i < hdr->e_shnum; i++) { - if ((sechdrs[i].sh_flags & shf_wx) == shf_wx) + if ((sechdrs[i].sh_flags & shf_wx) == shf_wx) { + pr_err("%s: section %s (index %d) has invalid WRITE|EXEC flags\n", + mod->name, secstrings + sechdrs[i].sh_name, i); return -ENOEXEC; + } } return 0; @@ -3825,8 +3828,10 @@ static int load_module(struct load_info *info, const char __user *uargs, char *after_dashes; err = elf_header_check(info); - if (err) + if (err) { + pr_err("Module has invalid ELF header\n"); goto free_copy; + } err = setup_load_info(info, flags); if (err) @@ -3834,6 +3839,7 @@ static int load_module(struct load_info *info, const char __user *uargs, if (blacklisted(info->name)) { err = -EPERM; + pr_err("Module %s is blacklisted\n", info->name); goto free_copy; } -- 2.28.0