Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1768158pxk; Tue, 1 Sep 2020 07:22:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlbJZK2HVj8RCK7DlaUZQIgPkpXqP9gHYjb91ty7CCrLk1ITfRjtbZWbiifTVTbYx4KPp4 X-Received: by 2002:a50:cd08:: with SMTP id z8mr2010164edi.185.1598970134966; Tue, 01 Sep 2020 07:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598970134; cv=none; d=google.com; s=arc-20160816; b=dYaHXI172BnbXKZI86EzXM6SXpzWtzx3PwdRDwudOLWl2dN4fPkRGRyz4xDPROf/rT 3fwL3zK41Rqfh9kWqBEUBsLngRrfkCBXDrlZ5fDhSgOUzKzseVGjnMEnrWwaLkIVBXb8 XarVwT+iUsgRnutqskndIKUdFTenTllq9MVngxsZSYG5al6z+MKZYNXa8R3G2JivGi3t hRJY7ZH6f7cFJ8cVWQPSmf0sbRUvDDZwKtLQ/dcVxG0Aj11MzpP9DBpYt0Lzi86uynbI gjDRlk08fJ4ahwLuwnIxB+0WNqLzPrBAB+7pgklup60GPiXi19WeMPGfPEXVqnENOnti 7ADw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=9x5GQZUDU5BjdLr+3r7gDF+UAMK6klGVS9eeaOTcXK0=; b=MogauDnej4MGDaG42LgToz4VyWg/Qbp4mSgVDh87HyXq9kefqoOT5hFXzd6wUmwiUB lAaQTPKeCONXr0R0lMkFpVPfLuPFdqgFY3rsfVTCGAxDiRYiDvu5pfWq42+yFfG66Hh2 FMw4mMXiOdN5TwLKIKSo3la/zwwDONAdfkDlXLW13s9Vetw4ZhtJmMgcp6gUGqjX+0Pc 4xsvb8OI82YIuCdDP/8UNS81M2VwyeSJflCgAYcqxY6upjcmghXesTTEJ6C80baNa5HG CXfLqgXIbMl21ch5nWc1+Cf7HPae0kvE2Tta+iJMCK5UOAF8N9R1jGZGvADDGdzZ04sO hWLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KqyaZLt3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b3si707340edn.98.2020.09.01.07.21.51; Tue, 01 Sep 2020 07:22:14 -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; dkim=pass header.i=@kernel.org header.s=default header.b=KqyaZLt3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727881AbgIAOUw (ORCPT + 99 others); Tue, 1 Sep 2020 10:20:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:60926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727998AbgIAOP1 (ORCPT ); Tue, 1 Sep 2020 10:15:27 -0400 Received: from linux-8ccs (p57a236d4.dip0.t-ipconnect.de [87.162.54.212]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 97CBA20684; Tue, 1 Sep 2020 14:05:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598969142; bh=Syza0QjBGgPIriGEU3VpgNuhG+Ks2HlPQEx4xe3m7YY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KqyaZLt3GJqPFvUNSm3kEgCo12hW6iavpob7NR8+jZb3Wq1SDgtWFiDwv9Rf1YpeV +RAJSblpYg/45miZEvgGoNNCgH7oWC/pd5gs8+d3eAnFcmKUIGL2O/zOkpaOEBnY4e GSwLj8n4dsjiBgqIHu8FJYT94bKA7W8WzjVLfSG4= Date: Tue, 1 Sep 2020 16:05:38 +0200 From: Jessica Yu To: Qu Wenruo Cc: linux-kernel@vger.kernel.org, jeyu@suse.de Subject: Re: [PATCH] module: Add more error message for failed kernel module loading Message-ID: <20200901140538.GA9643@linux-8ccs> References: <20200831083705.20807-1-wqu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200831083705.20807-1-wqu@suse.com> X-OS: Linux linux-8ccs 5.5.0-lp150.12.61-default x86_64 User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Qu Wenruo [31/08/20 16:37 +0800]: >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 Thanks for your patch, agreed that there should be more descriptive error messages to help debug module loading issues. >--- > 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); I think it's OK to put pr_err and the format string on the same line. IMO the line break doesn't add much readability value in this case. Also, we have access to secstrings in this function. We can print out the section name with secstrings + sechdrs[i].sh_name in addition to the section number, I think that would be helpful. And can we reformat the message to start with the module name, similar to other pr_err() sites? i.e., pr_err("%s: section %s (index %d) has invalid WRITE|EXEC flags", mod->name, secstrings + sechdrs[i].sh_name, i) The rest looks fine to me. Thanks! Jessica