From patchwork Wed Oct 19 08:23:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5354 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp297207wrs; Wed, 19 Oct 2022 05:28:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM498NIG0JdTlClph8IaynjW5kXrtitj0UbUOxTlCvhgezrb59ijPk6hr49RV1U05fjxtTp+ X-Received: by 2002:a17:902:9b82:b0:183:fffb:1bfe with SMTP id y2-20020a1709029b8200b00183fffb1bfemr8262054plp.173.1666182516798; Wed, 19 Oct 2022 05:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666182516; cv=none; d=google.com; s=arc-20160816; b=Y0A8dNNWicuIzqKrDBg682geE3B6RQG24djOOpKVbu0XxLBUsdbs+wUrzbl5AyVybg aQnxcGneLY8BfzpQwGSLnqyLUtLtmJUFQFuOm8yFWVQBJXm7iZYPtlsdiLjlGBf5dvjc VoyppQl1uxIYPyj9rP2opX8co+KhzL86kDNkal5KPP7q78/mqzfKvCDGQrvuF0W7WJ2u 20G6ruxRQIYNEXwbNtfyTekI5TMWBEOoXhmsai8nm1HQvzA/u8N5v9Va9qTAw8MHfedt FeckrVeoLE2xGIfqWcC4utkT4q4Co2OTW43vKtb+0q/Tq/agxR+nUpbbrYFY4Slk6bgx gAbg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S5xSSGh7EJ6oAJETeInC6CrJLz3f2vN3RwUFl3HvtN4=; b=eKSEJc3BAbcukcX4TlqAqeP/I7etyteACA5IsYxK5ORKe8KJ/06KdlS+Tf2j8rp4bp //YFMvuffNa/A3uU98JJ+SSI91r4RKnT5z0Mvl1yaACqGNDEguU5T8XYOt1Dhxxjea8p Qyd/n4PZkDJev2XAucLilHx5KKgmyPQofxiTQBAp2PPDCJEwYj6DT+6x0Aeh0w89bx2v 0jMCS/r8e+6oKTCCnckvTC68tC2yd3btKK8jWZT3N43x9cGjYmidtsCj9mjp+WwmuGbb gyKwIzljKOXn9YDuG4cvgAv8e7fUprn58Io7rq7VLFoyOT2ySO1RoKbiCtxEi0/lZrBw HG0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1w0wdQP1; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020a17090311ce00b001789fa8f90esi20935314plh.408.2022.10.19.05.28.22; Wed, 19 Oct 2022 05:28:36 -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=@linuxfoundation.org header.s=korg header.b=1w0wdQP1; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbiJSMTN (ORCPT + 99 others); Wed, 19 Oct 2022 08:19:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232902AbiJSMST (ORCPT ); Wed, 19 Oct 2022 08:18:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E00AFFF223; Wed, 19 Oct 2022 04:53:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EF687B822CE; Wed, 19 Oct 2022 08:44:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5408FC433D6; Wed, 19 Oct 2022 08:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169075; bh=rCyFVxv5D3nRejcezEL/j3R7yTl+gDdfILEu0MAjraw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1w0wdQP1vfGdVGhprDeEd14L0lB5Cv//SNYkZWTX6uyA6sOLQ8TEm5EonU2N36Qmf J6jMFObN+6Liy/L+GzN3POwGMGlvqi1BGhi/2RrbswEOpTdPtUq3U8X1x5W6GmK2uN 6a9ttUgsd7wyElex7kHOngXqTZFy5JnPvjpD1cxo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hyunchul Lee , Namjae Jeon , Steve French Subject: [PATCH 6.0 113/862] ksmbd: fix incorrect handling of iterate_dir Date: Wed, 19 Oct 2022 10:23:20 +0200 Message-Id: <20221019083254.912900126@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747118998859875043?= X-GMAIL-MSGID: =?utf-8?q?1747118998859875043?= From: Namjae Jeon commit 88541cb414b7a2450c45fc9c131b37b5753b7679 upstream. if iterate_dir() returns non-negative value, caller has to treat it as normal and check there is any error while populating dentry information. ksmbd doesn't have to do anything because ksmbd already checks too small OutputBufferLength to store one file information. And because ctx->pos is set to file->f_pos when iterative_dir is called, remove restart_ctx(). And if iterate_dir() return -EIO, which mean directory entry is corrupted, return STATUS_FILE_CORRUPT_ERROR error response. This patch fixes some failure of SMB2_QUERY_DIRECTORY, which happens when ntfs3 is local filesystem. Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") Cc: stable@vger.kernel.org Signed-off-by: Hyunchul Lee Signed-off-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/ksmbd/smb2pdu.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -3808,11 +3808,6 @@ static int __query_dir(struct dir_contex return 0; } -static void restart_ctx(struct dir_context *ctx) -{ - ctx->pos = 0; -} - static int verify_info_level(int info_level) { switch (info_level) { @@ -3921,7 +3916,6 @@ int smb2_query_dir(struct ksmbd_work *wo if (srch_flag & SMB2_REOPEN || srch_flag & SMB2_RESTART_SCANS) { ksmbd_debug(SMB, "Restart directory scan\n"); generic_file_llseek(dir_fp->filp, 0, SEEK_SET); - restart_ctx(&dir_fp->readdir_data.ctx); } memset(&d_info, 0, sizeof(struct ksmbd_dir_info)); @@ -3968,11 +3962,9 @@ int smb2_query_dir(struct ksmbd_work *wo */ if (!d_info.out_buf_len && !d_info.num_entry) goto no_buf_len; - if (rc == 0) - restart_ctx(&dir_fp->readdir_data.ctx); - if (rc == -ENOSPC) + if (rc > 0 || rc == -ENOSPC) rc = 0; - if (rc) + else if (rc) goto err_out; d_info.wptr = d_info.rptr; @@ -4029,6 +4021,8 @@ err_out2: rsp->hdr.Status = STATUS_NO_MEMORY; else if (rc == -EFAULT) rsp->hdr.Status = STATUS_INVALID_INFO_CLASS; + else if (rc == -EIO) + rsp->hdr.Status = STATUS_FILE_CORRUPT_ERROR; if (!rsp->hdr.Status) rsp->hdr.Status = STATUS_UNEXPECTED_IO_ERROR;