Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3037315rwd; Mon, 22 May 2023 07:52:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7NvvcnkKng4RICLniJOUnomh9jWZR3UVk2yRPoTpyKCXqztcpihpIrbA1DB0Ntq3l5CYh9 X-Received: by 2002:a05:6a00:98c:b0:646:59e4:94eb with SMTP id u12-20020a056a00098c00b0064659e494ebmr15227111pfg.15.1684767127213; Mon, 22 May 2023 07:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684767127; cv=none; d=google.com; s=arc-20160816; b=ViTY3/u5SzxspYw5d5dFTr7TDdk5aXPwnSoc3zlw64K9F6Rd8WraVbta/vA42s2EW0 grmeLnlsG334+nW95l66RzgeQk4gcPWqIrJhcX1Vn8BClNJCThNOLjbmDLBcpVuhM79B Ov9A/2YwBQVrVzXNWnlUlLi87P5NLI6YMIE+E0Uld+lSg2IYwdcP47mjbCnonfaScTUL 74aBAU/MpvIJ4vBqDbczYfAS25KZY3EdWFfjaVukMX1wPzZecPHOzWKlgayjS7Fqi3Hk 2ZJJJcnbW7+uProuUXRbd56Yo9vDFrPf5i1hrAVD9nx6xALxtus3bSN7VC9fHCgFiXCE /+tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:from:organization :dkim-signature; bh=AFW+IZL67Cz0xRBwmMsauHMgB+wZd79K6KlpZee9jmw=; b=yl7kNY5p0QC1E+TXQAWUe2H34M4HaOwoPvJHaSDMTQQSF7z2LrC7IxfHXnlRg90OMT 4DH3lDcK+K8D1XbMyMoIStyLHo4q0cVMJrqDOV+wzZldyhH+CVJGFeOPErmaiQk5BSC8 fEBs+1w849gPJ29uJjocxugAD9QgELmgSv8XyqnYoIB09Qu58y0J96v4col2pemkD/9I 2Pu6+h7VgH/crQ1yus2wWMdQjvC9ypeIid6KFWCDu1Mt7e62W2bSU1/W6bSN56vwe4n7 GwkdNO9/gueOsExyBTRfVQMukbA3YAQzhpb1LqeY2axBOs+mqwuK3R9DyO8s9jEz51b/ 7Xig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TWSGiD86; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a68-20020a621a47000000b0064b032430cesi1406415pfa.133.2023.05.22.07.51.54; Mon, 22 May 2023 07:52:07 -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=@redhat.com header.s=mimecast20190719 header.b=TWSGiD86; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233871AbjEVOl0 (ORCPT + 99 others); Mon, 22 May 2023 10:41:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjEVOlZ (ORCPT ); Mon, 22 May 2023 10:41:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77292DB for ; Mon, 22 May 2023 07:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684766436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AFW+IZL67Cz0xRBwmMsauHMgB+wZd79K6KlpZee9jmw=; b=TWSGiD86axuzWHWOrAduiKv5D+O0uq5Bs5eFDy8RV1URxi2HliujPrKeX9lwI3KmENpDF+ NSHMHWv3fAOZq1Q+7MCjSsHEHdTV9wHFyr6NFTSNS3iEbHY4wcCxPl8KvTbkqmmHd4rQEc 5UqsvuQhVK3OaG1gg7a9ikCTBMuNNF8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-564-Ig3pnr3WNRKXjMESuYRgaA-1; Mon, 22 May 2023 10:40:33 -0400 X-MC-Unique: Ig3pnr3WNRKXjMESuYRgaA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B189D38025F5; Mon, 22 May 2023 14:40:32 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4895C40CFD45; Mon, 22 May 2023 14:40:31 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells To: Shyam Prasad N cc: dhowells@redhat.com, Steve French , Rohith Surabattula , Paulo Alcantara , Tom Talpey , Jeff Layton , linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2811950.1684766430.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Mon, 22 May 2023 15:40:30 +0100 Message-ID: <2811951.1684766430@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Fix cifs_limit_bvec_subset() so that it limits the span to the maximum specified and won't return with a size greater than max_size. Fixes: d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather= than a page list") Reported-by: Shyam Prasad N Signed-off-by: David Howells cc: Steve French cc: Rohith Surabattula cc: Paulo Alcantara cc: Tom Talpey cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org --- fs/cifs/file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index ba7f2e09d6c8..4778614cfccf 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -3353,6 +3353,7 @@ static size_t cifs_limit_bvec_subset(const struct io= v_iter *iter, size_t max_siz while (n && ix < nbv) { len =3D min3(n, bvecs[ix].bv_len - skip, max_size); span +=3D len; + max_size -=3D len; nsegs++; ix++; if (span >=3D max_size || nsegs >=3D max_segs)