Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1698463rwb; Sun, 15 Jan 2023 02:50:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXs4GKv33yZfk/Mk5m961JZK6PoAHYZ48OdUglL9mSiXPem4eUZhYfAExUCbyMwfkYeTKIdy X-Received: by 2002:a50:8d8d:0:b0:469:15eb:16fa with SMTP id r13-20020a508d8d000000b0046915eb16famr71613059edh.13.1673779851695; Sun, 15 Jan 2023 02:50:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673779851; cv=pass; d=google.com; s=arc-20160816; b=DfxOtdken4JZApGlb+6wufc3CPTtFJ6iazOIIvmVh6+spaPW1xSBg9LG0duHuGQ6PP xgJ+BjjpSBpx+uyUtTNQ60AF780uJdYaAIfAKnK2M3jA6bA4z1SHk5eddt7LGW1XM9dd x4bcIWYbLwiKjyBd/jxYp8MBOVAj5nS9ZkT1EEIUVEuUwYFwY3h4tSLEZHe83oyWj8AA oYl781ftoZp2lk6bPkSVrlyOP1Qp6hqquMc2mW+ztpCe+NFURVELhkTx10hdUaYQjvBF qRHTdMyWAQr8RvR8yhS28relStbsCb9b1R3Ex7VZQUqdk+R6zgFxQcSNx+/SS/NWJQKY gaeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yBv7BL9Uf6cXj9khn04VzCBRpFusMoYQVfaaytM5MVY=; b=RtUdzaXGf6Hhv5kwiha6iahdmQj5YM9NFC8+5y2RfFS7Sq4lhgG16wgD5sSxoyWMTR suGTk79/YxyS4NU4N7AfJUl5sPHlzpIVcBu1IM6Np6hrGM0NsMXWDiHoDUSN1oxd07yg gp8VqArlC0D8v+p504wIaNkOP8yqJKSNTkNgUvr5VsGh00Lf2uvZ+YQSpC3XMYgAfTaH N3jK8G42CvjBl1m8+nXqgz99iKc44bhikPsXFplKHtZVJNbS8A4Bm6pNFOpS22pkdptI I2Vh7vfi6+NC13uDYS5uRhbgt/mheKMAgxR7keMXUuyS0T5kFbkImKNjOaa2aIFurRMR eOfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=HtRWhX87; arc=pass (i=1); 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=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fj27-20020a0564022b9b00b00499c322a9c5si2732665edb.85.2023.01.15.02.50.38; Sun, 15 Jan 2023 02:50:51 -0800 (PST) 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=@outlook.com header.s=selector1 header.b=HtRWhX87; arc=pass (i=1); 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=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231223AbjAOKcv (ORCPT + 52 others); Sun, 15 Jan 2023 05:32:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230453AbjAOKc1 (ORCPT ); Sun, 15 Jan 2023 05:32:27 -0500 Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01olkn2045.outbound.protection.outlook.com [40.92.98.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBAC1CDF4; Sun, 15 Jan 2023 02:32:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jgBx+uSFDs3IRKmTXkP822He34PEHT84/IOiMSGekMG0kKmjweShw3scks6P8dv6yG4zax0jzIjThC4CBzjm2a9hom9YPTTcWTmVnWP0vI/haTUutme55YVNPeQFy3hM6262FiH5aLD1hq6oIhZxBSdVOxDtkvTGygeUZxw0axmkVsjaAQUxif+QQ89/5OqgNsmk+EZVZLOcuZ7LgOv836+9lJoHV6641t3e992X4vB3Obc3l98RYD+1eDB5wI+vbWBTl+NxoGHhpumhMerg940F8wQi+4krBauMV1tfqYtbMeq2szv0v6BLOZkKqaWE+op7UH6cbDw4HpuaUgzeug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yBv7BL9Uf6cXj9khn04VzCBRpFusMoYQVfaaytM5MVY=; b=DezYgFGylCN+WWPi8yreaLdjNh3uvO+MV2m7EoOrVfNZ3tBKHQatbO3hLVvG/WFqehbDx4Q1csDoxTz3gzGTzVx8Tyeqnchc7XyYTfB8xvNaWj/oPoYGXowf9utWLf8IRNNpqwZEe+v1rg9bkwGSBw1Rf82yGeYzrPPG/sde8XcqvmpQxORYWWoVCCMs5xMoyT1LLejIICtojP1Cbp4DUmevW50qLvRHA/DJ35jZ2kjkRsVknmVgt1Ch6BosdEfo8gLHnOGoYYabk7cSAuCp720K89M3EHJJUm57PK+L0DpvI/oMmQN7YliK6vXu+aamv5o4HYEClyZfhckhSomMVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yBv7BL9Uf6cXj9khn04VzCBRpFusMoYQVfaaytM5MVY=; b=HtRWhX87r/IiFjroNNQQTkq7uROq4LkixilqMwVib7Z5hRLSW9+fNVvM9HZIdHo6F5lNr++teX20VOcgPBLoGwsGEc3uPMjLSWky3SWDnMvCTTL2FBuI5sMbGxdw4yPsTSmsVQ9G3BSUTontwmn8+ZYEgMSoaFB88CMrzyXfAowTjGXAaAkR0T5wW0pect+fGe39J815n+/u6NiIKJZYCqEWa4LHNbdu0hx/1IxCw1w9/ryEUSismo0aQ4kkEqvWSwCDDvtTagpPTMAYEcLMm2bg9XthUzTDk1U3oq67kZe+J89iuJhZk4Xxyg3ux7lP2d64SD3SUAeevrTCxmIThA== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by OS3P286MB2025.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.12; Sun, 15 Jan 2023 10:32:24 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::ff96:9cb6:e047:c605]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::ff96:9cb6:e047:c605%4]) with mapi id 15.20.6002.012; Sun, 15 Jan 2023 10:32:24 +0000 From: Dawei Li To: linkinjeon@kernel.org, sfrench@samba.org Cc: senozhatsky@chromium.org, tom@talpey.com, hyc.lee@gmail.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] ksmbd: improve exception handling and avoid redundant sanity check in loop Date: Sun, 15 Jan 2023 18:32:08 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230115103209.146002-1-set_pte_at@outlook.com> References: <20230115103209.146002-1-set_pte_at@outlook.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [TLUMQ9VmFG2iXlqBs9WdQk1N+GaLwOZxb/cH16lS/eA=] X-ClientProxiedBy: TYAPR01CA0210.jpnprd01.prod.outlook.com (2603:1096:404:29::30) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20230115103209.146002-6-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|OS3P286MB2025:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a957baa-ecf4-4f4a-86f3-08daf6e3ca51 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VmSD1IAij1wTEhBFvMyP6VgzZg+Kzd0P5HQpsMkes71SiOF6BOk+cSxen4/T40okNhVcSqBXpyvG/6NK0thvVn/xDCZan7HdKCPoODYPa7qMqEMdB/liFkJRcuAm5x1buYy52ZlCfr8i9ocpkBZXezuUsYiXvst7mUWJG7yYZbK8e40AfRkJjj+BTRXAv0D93QGGpuiPbaetI4ycWsjo2yJR2PvrLMgLOkQQXmKIbomM4xHs1NCful9Z3DchPxgr+KMkoGOfhRFnfCkivLqi/yiuVEnm5jvtSSgGioGjdlgfGq2wFEcyL1XX1PurJ8PToeo5ldMuc10Jotd+winhf7URRPPxvSjjPm6OAYbWvLv7NsWSHCYF9RKDmIdiFet1v5p7PNErpEyLPq7EdeTf4OG205tRKN+gvrtrIXE52Erfg0meIrOHi9fwNbJ8kYcTnRRv1TMP5yZKPTh+IDI6yRngdaqQpj/rVICHzIYOHwn6EDNrrn8VV7PNOwdmKFzCiaEqU7ZNIFVSuS74sXJDP7F1WVAGZOd65B2riGI5UB2n53Rrbv/SgCJ6sYHzhgAwvbnKiNqfI8xtGDzWKcjaYYmfd02Ahe67LURpJqAn0HQ= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?DKlU+EVUHF653wYuNemROsio4rKomrRwmGl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vo?= =?us-ascii?Q?YQtRqPnPuSJrGmOGt/ziT6hYOKyVp5ruJ3vKUgjsP5puPrH6d1tPAYnttXxu?= =?us-ascii?Q?ta8PutpxfyT+gocGTtEWVQOwQxwjLT/0rXow5tQYQ+y3kf1DsHbW8lhwcEDC?= =?us-ascii?Q?Y6/G6oY7DxhWjbC4KqhHs57u0+MRadtNhBh1UkpwzcpNX+nWSIHccFNyZ/Sm?= =?us-ascii?Q?/T4eVCFf8pU0zvQwcg2MCPNfkIn7uDr+fm7eha/6l9JvoHD32nOzW/2loRYF?= =?us-ascii?Q?S77FYuM3pzA9vu8/zA5Eu205yMX0yhe/3BOmpWH9vAP5CbztNszhWsnkUNAR?= =?us-ascii?Q?mizIhVj2Z+ee7mVnL/6rprdb8TJ5DDahcPo3lmp5PGwhxaBvWg1m35atRCeV?= =?us-ascii?Q?as9y17bHAEDvam7XzWGcvp3qIA5KSmZiXOngeHW8AgztfFukE0tAAjHrZeru?= =?us-ascii?Q?GEY=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a957baa-ecf4-4f4a-86f3-08daf6e3ca51 X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2023 10:32:24.0883 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB2025 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 1. Sanity check on validity of hook is supposed to be static, move it from looping. 2. If exception occurs after kvmalloc(), kvfree() is supposed to reclaim memory to avoid mem leak. Signed-off-by: Dawei Li --- fs/ksmbd/connection.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/ksmbd/connection.c b/fs/ksmbd/connection.c index 36d1da273edd..b302de5db990 100644 --- a/fs/ksmbd/connection.c +++ b/fs/ksmbd/connection.c @@ -287,6 +287,12 @@ int ksmbd_conn_handler_loop(void *p) mutex_init(&conn->srv_mutex); __module_get(THIS_MODULE); + if (unlikely(!default_conn_ops.process_fn)) { + pr_err("No connection request callback\n"); + module_put(THIS_MODULE); + return -EINVAL; + } + if (t->ops->prepare && t->ops->prepare(t)) goto out; @@ -324,8 +330,10 @@ int ksmbd_conn_handler_loop(void *p) break; memcpy(conn->request_buf, hdr_buf, sizeof(hdr_buf)); - if (!ksmbd_smb_request(conn)) + if (!ksmbd_smb_request(conn)) { + pr_err("Invalid smb request\n"); break; + } /* * We already read 4 bytes to find out PDU size, now @@ -343,22 +351,18 @@ int ksmbd_conn_handler_loop(void *p) continue; } - if (!default_conn_ops.process_fn) { - pr_err("No connection request callback\n"); - break; - } - if (default_conn_ops.process_fn(conn)) { pr_err("Cannot handle request\n"); break; } } + kvfree(conn->request_buf); + conn->request_buf = NULL; out: - /* Wait till all reference dropped to the Server object*/ + /* Wait till all reference dropped to the Server object */ wait_event(conn->r_count_q, atomic_read(&conn->r_count) == 0); - if (IS_ENABLED(CONFIG_UNICODE)) utf8_unload(conn->um); unload_nls(conn->local_nls); -- 2.25.1