Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp214929pxj; Wed, 16 Jun 2021 00:18:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZYelwVfYvRmlCa2g4oDcj00RxSNKbpwYZijLeB4cRC2gXZ3xlbj5L2OS3biG8NKYirG9p X-Received: by 2002:a6b:3b05:: with SMTP id i5mr2523933ioa.135.1623827935833; Wed, 16 Jun 2021 00:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623827935; cv=none; d=google.com; s=arc-20160816; b=kC2NY7tQe9NZGg2K1jjHznuCALdVJwgJAnblYwE0Z3juRYWjzFyee9C41KioWag6ys 6cvPfGJ0HAKMESxC87im9wymBOHzbLW0oK2KkhB4wDBzk2teCCZXNNa0DxfVlbyKKt/2 gVfFtQS/8YcWmgLiBMNPBMMSISzdGbeuVI0Rnw9z7Z18tEb61tqT91XLzufrRwOR3nMm 0/N9ZceRvj+TTEvUD4Jh7F093+cj4jdMhJb60Xz4shpWOO5UVQAEsVsU915jM4WuRV3T 66Es/urHtkK9i/yun3Jg8CVMBcMroUaKN/6uGHimznBLWwgzUJ9Hj9+ltt7e1w5r1eAQ 3iOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=ll6o8Xs1DP78CCkRyeqXuwv66T21mfgRsoWtFK+uKls=; b=IxhMiNDwzaq/ahEV8BF020iUpBqhnNcghEXgq8GgPwalFyur9n/VAMUUsSoP4IpKN4 h5NI8aEN7weK+Xxg/CJKZZStSO4/yMgpccMMpfdB9brh2VJxJ14/QKeZBjUEyO0wVHg9 WPPXysQNKxrNPFwSTtSltkIUn3rSOGUh8C9OAlKnEJKVxQcuC9+CuGpjvWHtDnDAPMI6 KLiTu3CieCo4RsXST4hFAdYY1iE7qfe6u0SvBX0VVt/AF3wMy4kmlY8aGYKuZhcD99Yg 0MTfvcIOqyIvYjLVFibo7XM0acErofGCntsJAai0X/9XRK+PhXWQyeZwjyCwhiqMH7Xj f+dA== 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 w15si1369076ilv.111.2021.06.16.00.18.43; Wed, 16 Jun 2021 00:18:55 -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 S231513AbhFPHTO (ORCPT + 99 others); Wed, 16 Jun 2021 03:19:14 -0400 Received: from mail.loongson.cn ([114.242.206.163]:46802 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231239AbhFPHTN (ORCPT ); Wed, 16 Jun 2021 03:19:13 -0400 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxiuBtpclgNFkSAA--.27863S2; Wed, 16 Jun 2021 15:17:01 +0800 (CST) From: Tiezhu Yang To: Luis Chamberlain , Andrew Morton Cc: linux-kernel@vger.kernel.org, Xuefeng Li Subject: [RFC PATCH] umh: Check if sub_info->path is exist in call_usermodehelper_setup() Date: Wed, 16 Jun 2021 15:17:00 +0800 Message-Id: <1623827820-21248-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9AxiuBtpclgNFkSAA--.27863S2 X-Coremail-Antispam: 1UD129KBjvJXoW7GFWUtrWxKFyfXF47uFW8Xrb_yoW8JF1xpF W3Xr1ayr4rJFn2kas7A3Z5ur15Ar1kGF13XFZ7Z395A34kur1DXr48Ga409FW5KrWSkFW2 yr1Fvr4S9F1UGFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkv14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6r4x MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI 42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JU4UDLUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In call_usermodehelper_setup(), if strlen(sub_info->path) is not 0, but in fact there is no such file, in this case, there is no need to execute it, set sub_info->path as empty string to avoid meaningless operations in call_usermodehelper_exec(). Here is an example: init/do_mounts_initrd.c static void __init handle_initrd(void) { [...] info = call_usermodehelper_setup("/linuxrc", argv, envp_init, GFP_KERNEL, init_linuxrc, NULL, NULL); if (!info) return; call_usermodehelper_exec(info, UMH_WAIT_PROC); [...] } $ ls /linuxrc ls: cannot access '/linuxrc': No such file or directory Signed-off-by: Tiezhu Yang --- kernel/umh.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/umh.c b/kernel/umh.c index 36c1233..2312cc0 100644 --- a/kernel/umh.c +++ b/kernel/umh.c @@ -373,6 +373,17 @@ struct subprocess_info *call_usermodehelper_setup(const char *path, char **argv, #else sub_info->path = path; #endif + if (strlen(sub_info->path) != 0) { + struct file *fp; + + fp = filp_open(sub_info->path, O_RDONLY, 0); + if (IS_ERR(fp)) { + sub_info->path = ""; + return sub_info; + } + filp_close(fp, NULL); + } + sub_info->argv = argv; sub_info->envp = envp; -- 2.1.0