Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13037678rwd; Fri, 23 Jun 2023 14:45:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ797az+V0Lo2YlxnHmX6o34MjwFzx8Dutxk2+AkT1vJdrg73FVfW9iiUMcUD1h4b78y9Eiy X-Received: by 2002:a17:90a:1a03:b0:262:c2fa:b077 with SMTP id 3-20020a17090a1a0300b00262c2fab077mr379617pjk.18.1687556748497; Fri, 23 Jun 2023 14:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687556748; cv=none; d=google.com; s=arc-20160816; b=fH1g2u75dJ39Q4pIeq6l4iAzvA7m+xbCqKA5YmQ35nqZ177ebymcondohjGCXGMmNM EHh8bkPtVm2KJhIiqW3jMcIIZpU8/mX6YjAzAEsPEjHLA3v/KRoz1lTryQobEipzcYTF YlVoPVwg0rH59r4TxF4NB5T7g4nJMIInvdjkV0ArTNq/XNval8ZZAuQZWL2I/LFFNrfM 0b/kQMVVl4jLzWQgJB/CbrvgGg9pHpngnK1hDLqQoDND1qT4UW0p1vb6nNzfSGG7FZBg QEkK2mqzrIyU50cIW9YA5Ty3rM4DUoXB8DgI/5BT+yLTw+ey8IQkh1ueuYkl9oPr9irh IR/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/sSR85tujYuE7IR0tXwGOyW+CVKsM6am6F/jwXx6hVE=; fh=ojituO6zycijeJGO2jQfkYHTX5V9TkxkKCpW3Jq+Vm8=; b=VH9tyJojkCF+6/9q4YH+Odb7qhTOtLvGSH16hzOVroUSUCbA179DHzaavX/jFeWwPq +r2xTLl+4TJvWyQC+viwGbO6aZ+n3fDr1iYqx4hbXESLrFSaeXF6VHn4jF/8hlvN1IJ6 JeW7ULuO5wLfi1Y6Y6qrSO+yFj6wbuS5G4JXDNjEER8IAq4Rys+fZC6kCV+iHt0CO23z Pz517lr7JtbSMy7rM4dF5EFpiXNXIv6Yr2tBsC00UG268NeUvSmqpQoKh5E2vDM+ED3y 4b0VbBgnT3Pr6xwhXN81V3Gy03+Ju/AyKRHxmcJrw1Zzt4Cp1hzQ/vIBxasWbC3I1kqz qRdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=t8rfto8d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa2-20020a17090b4fc200b0025690b76c95si412648pjb.10.2023.06.23.14.45.36; Fri, 23 Jun 2023 14:45:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=t8rfto8d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbjFWVgB (ORCPT + 99 others); Fri, 23 Jun 2023 17:36:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232240AbjFWVfl (ORCPT ); Fri, 23 Jun 2023 17:35:41 -0400 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 446EDBA; Fri, 23 Jun 2023 14:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1687556140; x=1719092140; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/sSR85tujYuE7IR0tXwGOyW+CVKsM6am6F/jwXx6hVE=; b=t8rfto8dE4eHXsWiTeQEYtDaTTBBMyMEFepkoe2GJ0z9a4nYr9DMzdNN Gnk8TWTXGjM+NSZy4AcZrH3LkqKmzB3nVnFV+uKoLTPRqOvEugqcXijAV 7dzM8Crf2DQJM/gXhRehwefD4oRwF6hhxAMDu2HWk1t2or5lkte2mjoHJ Y=; X-IronPort-AV: E=Sophos;i="6.01,153,1684800000"; d="scan'208";a="12124977" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-pdx-2c-m6i4x-8c5b1df3.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2023 21:35:39 +0000 Received: from EX19MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2c-m6i4x-8c5b1df3.us-west-2.amazon.com (Postfix) with ESMTPS id 7670840D44; Fri, 23 Jun 2023 21:35:36 +0000 (UTC) Received: from EX19D002UWA004.ant.amazon.com (10.13.138.230) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 23 Jun 2023 21:35:35 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D002UWA004.ant.amazon.com (10.13.138.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 23 Jun 2023 21:35:35 +0000 Received: from dev-dsk-risbhat-2b-8bdc64cd.us-west-2.amazon.com (10.189.73.169) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 23 Jun 2023 21:35:35 +0000 Received: by dev-dsk-risbhat-2b-8bdc64cd.us-west-2.amazon.com (Postfix, from userid 22673075) id BE56C3A38; Fri, 23 Jun 2023 21:35:34 +0000 (UTC) From: Rishabh Bhatnagar To: , CC: , , , Aurelien Aptel , Steve French , Rishabh Bhatnagar Subject: [PATCH 5.4 4/5] cifs: Merge is_path_valid() into get_normalized_path() Date: Fri, 23 Jun 2023 21:34:05 +0000 Message-ID: <20230623213406.5596-5-risbhat@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623213406.5596-1-risbhat@amazon.com> References: <20230623213406.5596-1-risbhat@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Paulo Alcantara (SUSE)" commit ff2f7fc08268f266372c30a815349749e8499eb5 upstream. Just do the trivial path validation in get_normalized_path(). Signed-off-by: Paulo Alcantara (SUSE) Reviewed-by: Aurelien Aptel Signed-off-by: Steve French Signed-off-by: Rishabh Bhatnagar --- fs/cifs/dfs_cache.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/fs/cifs/dfs_cache.c b/fs/cifs/dfs_cache.c index 31b3dc09e109..1efba8ee86bf 100644 --- a/fs/cifs/dfs_cache.c +++ b/fs/cifs/dfs_cache.c @@ -75,13 +75,11 @@ static void refresh_cache_worker(struct work_struct *work); static DECLARE_DELAYED_WORK(refresh_task, refresh_cache_worker); -static inline bool is_path_valid(const char *path) +static int get_normalized_path(const char *path, char **npath) { - return path && (strchr(path + 1, '\\') || strchr(path + 1, '/')); -} + if (!path || strlen(path) < 3 || (*path != '\\' && *path != '/')) + return -EINVAL; -static inline int get_normalized_path(const char *path, char **npath) -{ if (*path == '\\') { *npath = (char *)path; } else { @@ -828,9 +826,6 @@ int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses, char *npath; struct cache_entry *ce; - if (unlikely(!is_path_valid(path))) - return -EINVAL; - rc = get_normalized_path(path, &npath); if (rc) return rc; @@ -875,9 +870,6 @@ int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref, char *npath; struct cache_entry *ce; - if (unlikely(!is_path_valid(path))) - return -EINVAL; - rc = get_normalized_path(path, &npath); if (rc) return rc; @@ -929,9 +921,6 @@ int dfs_cache_update_tgthint(const unsigned int xid, struct cifs_ses *ses, struct cache_entry *ce; struct cache_dfs_tgt *t; - if (unlikely(!is_path_valid(path))) - return -EINVAL; - rc = get_normalized_path(path, &npath); if (rc) return rc; @@ -989,7 +978,7 @@ int dfs_cache_noreq_update_tgthint(const char *path, struct cache_entry *ce; struct cache_dfs_tgt *t; - if (unlikely(!is_path_valid(path)) || !it) + if (!it) return -EINVAL; rc = get_normalized_path(path, &npath); @@ -1049,8 +1038,6 @@ int dfs_cache_get_tgt_referral(const char *path, if (!it || !ref) return -EINVAL; - if (unlikely(!is_path_valid(path))) - return -EINVAL; rc = get_normalized_path(path, &npath); if (rc) -- 2.40.1