Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3574425ybz; Mon, 20 Apr 2020 05:36:12 -0700 (PDT) X-Google-Smtp-Source: APiQypJHkAmdmNDqPz61jgX682Q+T+i0wMQB16wll2drk0bhVsq33GFTDqby9U7tokZddsDLcqzV X-Received: by 2002:a17:907:b11:: with SMTP id h17mr16773098ejl.371.1587386172254; Mon, 20 Apr 2020 05:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587386172; cv=none; d=google.com; s=arc-20160816; b=UF9S8gOxHOHEwpp5gozoFQK+Pgs3M1wOyUl3Q6krFQL/foCvb14KQVC9m54GG7JddJ C57WvKXhOzxhCuN5G4GdZ+pl+pyqaWms42F1Mjtpwp6TChhb/kpehOLYDaTHEYPlqFSP HwlsDWNcBy5MkIerfeVjMm4LlmNaEmM3tLCi/g1jEaUSfdXJsm4E1Dwai5arDKmuFkq/ oMLJdiZUAvD9x4OI26pxRXM0lkTRMlxvTzqZP2b0E7aE41xsnL5weKHjKy4MqV6WWfEU bsOD5c2INqQncMIbz2k8vckK44dZ5wJHPfkQQgfx99JNA35kX7wJLsZ4oYpC41yrbyyN 9EuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=9LcX1OV0o0SY/bZBZxPQDORiGfPeCiS+RI5q+jylYZk=; b=oCg9XbH1lykJ7cW2ic7rVf4qFgqaWLkBmNOei7cAxY6BGnkG4N05PAnnboTSZryEOJ hnafItKlDrtf2nkjokViYmBUH9ZbHO+/m/U3zxVUB+8e3NsTm1pOYpYbrQcpvrYMONZJ ud9Yi7IRrA3bul6hXk+Nb7H1ZtMj2+hDLhjHTZ4NC8bmKxCnmNw4+U1/lCwGi3RNZ/tN f67Con/4RBLLqrUeCAKvgi8nMsC68mH6F+PLigIHMrln+SdqbKEAHXPQ0HWPXPzU4GXw TjdhZyVxyHq7+YGYCwxTJf82DB2stFk5va+Sv9KIA1GBaofP73SlUj0zkKuvWKjJtDQQ jLDg== 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 oh24si417054ejb.531.2020.04.20.05.35.49; Mon, 20 Apr 2020 05:36:12 -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 S1726754AbgDTMeD (ORCPT + 99 others); Mon, 20 Apr 2020 08:34:03 -0400 Received: from mail.loongson.cn ([114.242.206.163]:52242 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726615AbgDTMeC (ORCPT ); Mon, 20 Apr 2020 08:34:02 -0400 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxb9uzlp1eHSgqAA--.29S5; Mon, 20 Apr 2020 20:33:59 +0800 (CST) From: Tiezhu Yang To: Luis Chamberlain , Shuah Khan , Andrew Morton , Jessica Yu Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Elfring , Xuefeng Li Subject: [PATCH v3 3/4] kmod: Return directly if module name is empty in request_module() Date: Mon, 20 Apr 2020 20:33:54 +0800 Message-Id: <1587386035-5188-4-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1587386035-5188-1-git-send-email-yangtiezhu@loongson.cn> References: <1587386035-5188-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQ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 4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBI daVFxhVjvjDU0xZFpf9x0pRwqXdUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v3: - no changes v2: - update the commit message to explain the detailed reason kernel/kmod.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/kmod.c b/kernel/kmod.c index 3cd075c..5851444 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c @@ -28,6 +28,8 @@ #include +#define MODULE_NOT_FOUND 256 + /* * Assuming: * @@ -144,6 +146,9 @@ int __request_module(bool wait, const char *fmt, ...) if (ret >= MODULE_NAME_LEN) return -ENAMETOOLONG; + if (strlen(module_name) == 0) + return MODULE_NOT_FOUND; + ret = security_kernel_module_request(module_name); if (ret) return ret; -- 2.1.0