Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp816803pxk; Mon, 31 Aug 2020 01:38:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIUiy9FCtzqqkKBxO78UV0EgP2/wkEiyQIXm9eQaRqq884jB6qBZjU5K1Afzh6KrcprmBS X-Received: by 2002:a05:6402:31a3:: with SMTP id dj3mr202417edb.73.1598863111257; Mon, 31 Aug 2020 01:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598863111; cv=none; d=google.com; s=arc-20160816; b=exTJcOhouBZTOVYSL8/3LJHZKNXea4d8yfl/+gBJrfLcCRf1ZndFGQ2zWip5+gGOKv Km0fjKzYqFVgm9u+qRejVz2OFH28I4/6q2Xqtnq5fidtf2MSnv7RkSczujFq85HGK2pA e6l1erlZchj6C+HJXF/qbgZJgef+Dq9SdH7M7zxZVmoombp2f/AhIWlK9ZHuQmFAVH7j +gGOOpe5ZvRwBOq3EYotn2E6Go/Tkzta2AQPX6is6jNK6/6oMaa9rpo5h+yH1bMJZ5JD J5ZQGBvhX4EvKstHlBSLQiyg+EZPORphcAWhaEscb2U7p/t6YTEtQWV9wFbFed63sBKF XNug== 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=mmcCYltBpXqbHVl8NfymqC0QUaiCk4yBqr1sGBSRz7o=; b=vWY7a1J2/mc6iJBfkrzYdrQygNvymYqDY646HtztrbJx4i9xMtcF/PESAZ6VfNfZyV y3klT9cWG/y3wnLsT5AabDZI5hlt9h/bx42kz+2uf4RScusJ5OD9XrMLtH4FQ9zNZKNK RJOgPk/Pax4Z+6uLtSfLMVmfvB0AMQ+khRkAAyHLYndMgpIDfYeui2/w++YcCqcaGpNs kk2nfkGShXPOhaqj0KHFrm+aXp4dvdR6frz/wN84boM+ZfgpUXl/usT7pQx9z2wS/Vgn RCO8YpjwnGtM4DeloXuBnztObDgGCMOeds9RDDwMa09iyYUAmhQ8B+FhgExpoANtAcqT hBiA== 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 p7si5129331ejo.392.2020.08.31.01.38.07; Mon, 31 Aug 2020 01:38:31 -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 S1727810AbgHaIhP (ORCPT + 99 others); Mon, 31 Aug 2020 04:37:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:40542 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726102AbgHaIhO (ORCPT ); Mon, 31 Aug 2020 04:37:14 -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 470B8B5B1 for ; Mon, 31 Aug 2020 08:37:47 +0000 (UTC) From: Qu Wenruo To: linux-kernel@vger.kernel.org Cc: jeyu@suse.de Subject: [PATCH] module: Add more error message for failed kernel module loading Date: Mon, 31 Aug 2020 16:37:05 +0800 Message-Id: <20200831083705.20807-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 --- kernel/module.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 8fa2600bde6a..204bf29437b8 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2068,8 +2068,12 @@ 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( + "Module %s section %d has invalid WRITE|EXEC flags\n", + mod->name, i); return -ENOEXEC; + } } return 0; @@ -3797,8 +3801,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) @@ -3806,6 +3812,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