Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp186584ybh; Tue, 17 Mar 2020 21:00:30 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs50kNgx7CthprgyTIoPVPTOV/SSI3JooeqABIsLDNpviECijIB9bZGPTq8XKi7QMNeFOWt X-Received: by 2002:a9d:5ad:: with SMTP id 42mr2307369otd.231.1584504029883; Tue, 17 Mar 2020 21:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584504029; cv=none; d=google.com; s=arc-20160816; b=v/8OL5Ygr3YqDZJ6melD737/5wKP69Nyjdzb5RcCGrltWoHU7zGhwANTcxcUDSjZYg q8Yqu8m5RbwK4Obv135WCl17TNN7RfcrMLSN7KUNZerzYKbWDY9V7HAo2tlFrEbCfEXP YXoPVPlt3fL5U1PbntnzQcWtrINj2auqL1PCA9xv2NdGLqCnReXz8t5CGStGfMWzNjRh sylAuzaI5Xa6CHyS4VV76ZERSUF8u7RJKz9tCo9Z6tXVxUIweMsRN0GAMqzJc5ZAL5pj SMQ5OsOjKav/qzTvjHEFGylXcs7snucJkQ8HWlD6mSvbpwYyClYDsrp0Y0nNrqrLXqM0 Xzqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:date:message-id:to:subject:from; bh=lGN8JIih8566UJRFmZO7gqiQIz6hijoHp/fEYMN+16A=; b=ndneF4Zg3h3mCHtZjnJjisME+YzkQU+dAoXEw593kx6tIkkAlmKqMKHh3H8TJ3xGEj 3TAADdbRGecKjnym+fpotwUH9Ht9o3mn8kk4QMbaEwal3LpQ8dkNuPXKdgPmV6KwJpz1 gN45jZ6J0N5zjbBlJc0T6rvkhxh1Se76ffyerDR6n4ly1Pn4cSryVxsFG2EzZw0TQCsM EnYv9kfPdwempSYTHMo9dyqAcrcXBeuc6xM6JWPZOqXjr2A5VgCZrPCGD/3MG2c5lTi5 F/ecK+4k89aTioy+k49R+UI5pnuQb7MCv/sFwPFrn2BT9Z3thlMWTrh6MJAN7K6Db/4g W1VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97si2505381oth.209.2020.03.17.21.00.18; Tue, 17 Mar 2020 21:00:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727291AbgCRD7b (ORCPT + 99 others); Tue, 17 Mar 2020 23:59:31 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:11716 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726682AbgCRD7b (ORCPT ); Tue, 17 Mar 2020 23:59:31 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8E4C28FB8D73FE15242A; Wed, 18 Mar 2020 11:59:27 +0800 (CST) Received: from [127.0.0.1] (10.173.223.48) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Wed, 18 Mar 2020 11:59:20 +0800 From: Yilu Lin Subject: [PATCH] CIFS: Fix bug which the return value by asynchronous read is error To: , Steve French , , , Message-ID: Date: Wed, 18 Mar 2020 11:59:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.173.223.48] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch is used to fix the bug in collect_uncached_read_data() that rc is automatically converted from a signed number to an unsigned number when the CIFS asynchronous read fails. It will cause ctx->rc is error. Example: Share a directory and create a file on the Windows OS. Mount the directory to the Linux OS using CIFS. On the CIFS client of the Linux OS, invoke the pread interface to deliver the read request. The size of the read length plus offset of the read request is greater than the maximum file size. In this case, the CIFS server on the Windows OS returns a failure message (for example, the return value of smb2.nt_status is STATUS_INVALID_PARAMETER). After receiving the response message, the CIFS client parses smb2.nt_status to STATUS_INVALID_PARAMETER and converts it to the Linux error code (rdata->result=-22). Then the CIFS client invokes the collect_uncached_read_data function to assign the value of rdata->result to rc, that is, rc=rdata->result=-22. The type of the ctx->total_len variable is unsigned integer, the type of the rc variable is integer, and the type of the ctx->rc variable is ssize_t. Therefore, during the ternary operation, the value of rc is automatically converted to an unsigned number. The final result is ctx->rc=4294967274. However, the expected result is ctx->rc=-22. Signed-off-by: Yilu Lin --- fs/cifs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 022029a5d..ff4ac244c 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -3323,7 +3323,7 @@ again: if (rc == -ENODATA) rc = 0; - ctx->rc = (rc == 0) ? ctx->total_len : rc; + ctx->rc = (rc == 0) ? (ssize_t)ctx->total_len : rc; mutex_unlock(&ctx->aio_mutex); -- 2.19.1