Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp483449ybz; Wed, 22 Apr 2020 02:03:06 -0700 (PDT) X-Google-Smtp-Source: APiQypJ1l3g1LNCD7BqNotFJIxbaVk+w7fUxOtttzQPF68StpbO9XYFIt/ssBTsLcPCyFAXQba8c X-Received: by 2002:a17:906:548:: with SMTP id k8mr24429147eja.259.1587546186106; Wed, 22 Apr 2020 02:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587546186; cv=none; d=google.com; s=arc-20160816; b=J46Z+R2M/yQV2eJwqI9eNE+AUQxqRN9wfjleL3LCysasdyNVo7GEnJf6kYhq9/4zWN DYXWZ3nI0YtmGig2cKGD4C9dQHj2bncCLQoVw188xy86+0HOMu/FnKx+qowzxqsP06W+ PitzeWXmx7E3zK0l2rIp7hNQ7A96Yt7ACD7Np8nzk6klO7pmU+KHx9P0jHV7N7Wi0Fe3 GyFNPKYTorie2fkd5GSilk/H7KUhv0J3Asun61MZ7usS89JkGiSebfq7aL8EdCcgxS+G 8kRRfY9i+p3NZf2sQPqvsSqsj+Dy7xHj8S6sDIioO61xC8FsfPhFFFvyx1BIF/I0wpv/ yg3w== 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; bh=kLNU6bywMxPQAzhQibyTFEQXB5wKYkebBNpzsfqmEsI=; b=NXldZtZPJa6l1irfFoJhlJ4gclyMyjkgHvgqdib96VF7V+pwFq43k8BHYvmw+evOuM 2PXYsL6wZ0IAXAyHB/+WtoymHJl5V5m+xUOAEJqRM3286oF4D1U7GlOQcI1QxRHQhVmM SPaM0GNPxOOX1Tmm87EnhXwR9sMxAY/1j7R19BuHubIJOIdmfp1iH23F1n78mon5YFpx eKXn8LgmnhmOWabX6Q74WhaFJYKOJoGgPZyUYLspAxZc1ggAaRRjWZn7nFWKdgvIj6MT VB+gGXFKWq9YlAQeAxZYAcG+1E0DHZXb1Xpeq1cb2m/vFVaO3yH6Oa0ttIFyGcnq61X4 Pn2w== 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; 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 r21si3346856eju.300.2020.04.22.02.02.42; Wed, 22 Apr 2020 02:03:06 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726451AbgDVJBn (ORCPT + 99 others); Wed, 22 Apr 2020 05:01:43 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45749 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbgDVJBm (ORCPT ); Wed, 22 Apr 2020 05:01:42 -0400 Received: by mail-pg1-f196.google.com with SMTP id f20so746597pgl.12; Wed, 22 Apr 2020 02:01:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=kLNU6bywMxPQAzhQibyTFEQXB5wKYkebBNpzsfqmEsI=; b=BHYtNJtexUjAkRn8xHYcbDD0eUpRuRFubbD6k4HJ4EmrbPRmWfzQ7V7vm6jSBVZMHE NH/K6xdpCnujf5YBIwskzoyEQoWXF2TB1AesH/NUjmZSiBW5yuFG/iuMD/oyZ9VdNv1d Ip1AkC9IoGKXmvYNO6tEI1mlg/juFw0fBRwQ+3UTQIgZQ831gfTzHzAmte5KS/wiO47Y 1VIoNWNZrxdk0HO+BJ9YkmeRO8boukCh+TpgADBYVICnF1EXBaa4qdO/uHDKWx+U4vT0 7PJnwlDf4OrJlcrgsIRUvHPOlRq4bfRGVxJaThDyXXd1lvrgHLsBaLBxKD7AagEnv9fn SThA== X-Gm-Message-State: AGi0Pub2vglTjJtiygS5TrskUE0bDTOYA++ep3Wh1GiGQljEaDJLc//Z bfpNlM5/Lj9HheMh2vXoCqE= X-Received: by 2002:a63:79c9:: with SMTP id u192mr24835648pgc.7.1587546100119; Wed, 22 Apr 2020 02:01:40 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id r13sm4683580pgj.9.2020.04.22.02.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 02:01:38 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id B5C20402A1; Wed, 22 Apr 2020 09:01:37 +0000 (UTC) Date: Wed, 22 Apr 2020 09:01:37 +0000 From: Luis Chamberlain To: Tiezhu Yang Cc: Jessica Yu , Shuah Khan , Andrew Morton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Elfring , Xuefeng Li , Al Viro Subject: Re: [PATCH v3 3/4] kmod: Return directly if module name is empty in request_module() Message-ID: <20200422090137.GW11244@42.do-not-panic.com> References: <1587386035-5188-1-git-send-email-yangtiezhu@loongson.cn> <1587386035-5188-4-git-send-email-yangtiezhu@loongson.cn> <20200420181931.GJ11244@42.do-not-panic.com> <675147f7-2762-c574-4c3d-de6b25a5a44a@loongson.cn> <20200421144931.GA20103@linux-8ccs> <13aeb92d-047f-29a4-4d18-dcbd0519a218@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <13aeb92d-047f-29a4-4d18-dcbd0519a218@loongson.cn> 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 On Wed, Apr 22, 2020 at 04:55:34PM +0800, Tiezhu Yang wrote: > On 04/21/2020 10:49 PM, Jessica Yu wrote: > > +++ Tiezhu Yang [21/04/20 11:07 +0800]: > > > On 04/21/2020 02:19 AM, Luis Chamberlain wrote: > > > > On Mon, Apr 20, 2020 at 08:33:54PM +0800, Tiezhu Yang wrote: > > > > > If module name is empty, it is better to return directly at > > > > > the beginning > > > > > of request_module() without doing the needless > > > > > call_modprobe() operation. > > > > > > > > > > Call trace: > > > > > > > > > > request_module() > > > > > | > > > > > | > > > > > __request_module() > > > > > | > > > > > | > > > > > call_modprobe() > > > > > | > > > > > | > > > > > call_usermodehelper_exec() -- retval = sub_info->retval; > > > > > | > > > > > | > > > > > call_usermodehelper_exec_work() > > > > > | > > > > > | > > > > > call_usermodehelper_exec_sync() -- sub_info->retval = ret; > > > > > | > > > > > | --> call_usermodehelper_exec_async() --> do_execve() > > > > > | > > > > > kernel_wait4(pid, (int __user *)&ret, 0, NULL); > > > > > > > > > > sub_info->retval is 256 after call kernel_wait4(), the function > > > > > call_usermodehelper_exec() returns sub_info->retval which is 256, > > > > > then call_modprobe() and __request_module() returns 256. > > > > > > > > > > Signed-off-by: Tiezhu Yang > > > > Thanks for looking into this. I still cannot find where > > > > userspace it returns 256. Can you? If I run modprobe without > > > > an argument I see 1 returned. > > > > > > > > At least kmod [0] has a series of cmd helper structs, the one > > > > for modprobe > > > > seems to be kmod_cmd_compat_modprobe, and I can see -1 returned which > > > > can be converted to 255. It can also return EXIT_FAILURE or > > > > EXIT_SUCCESS > > > > and /usr/include/stdlib.h defines these as 1 and 0 respectively. > > > > I'm also seeing modprobe return 1 as exit status when I run it without > > arguments. I don't think the 256 value is coming from modprobe though, > > see below - > > > > > > https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/ > > > > > > > > Luis > > > > > > Here is my understanding: > > > > > > When build and execute the following application, we can see the > > > exit status is 256. > > > > > > $ ./system > > > modprobe: FATAL: Module not found in directory > > > /lib/modules/4.18.0-147.5.1.el8_1.x86_64 > > > exit status = 256 > > > > > > $ ./execl > > > modprobe: FATAL: Module not found in directory > > > /lib/modules/4.18.0-147.5.1.el8_1.x86_64 > > > exit status = 256 > > > > I am going to guess this has something to do with how system() and > > waitpid() (and the wait family of syscalls in general) encode the exit > > status in their return values. According to their man pages, you need > > to use the appropriate WIF* macros to get the actual exit code of the > > child process. > > > > From system(3): > > > > the return value is a "wait status" that can be examined using the > > macros described in waitpid(2). (i.e., WIFEXITED(), > > WEXITSTATUS(), and so on) > > > > From waitpid(2): > > > > If wstatus is not NULL, wait() and waitpid() store status > > information in the int to which it points. This integer can be > > inspected with the following macros (which take the integer > > itself as an argument, not a pointer to it, as is done in wait() > > and waitpid()!): > > > > WEXITSTATUS(wstatus) > > returns the exit status of the child. This consists of > > the least significant 8 bits of the status argument that > > the child specified in a call to exit(3) or _exit(2) or > > as the argument for a return statement in main(). This > > macro should be employed only if WIFEXITED returned > > true. > > > > In your test code, you are reading &status directly. To obtain the > > exit status, you need to use WEXITSTATUS(status), or right shift the > > value by 8 bits. That gives you 1, which was the original exit code > > given by modprobe. That's why you see an exit code of 1 when running > > modprobe directly and you see 256 when using system() and waitpid() > > and don't use the WIF* macros. > > > > As for why __request_module() returns 256, I am guessing this would > > come from kernel_wait4(), but I did not dive into the call path to > > verify this yet. > > +Cc Al Viro > > Hi Al, > > When module name is empty, __request_module() returns 256. > What do you think about this case and patch? > Thank you very much for your attention. Its because of an old issue umh.c, I'll send a patch. Luis