From patchwork Thu Feb 22 00:50:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Ruffell X-Patchwork-Id: 1902553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TgF230sVrz23hR for ; Thu, 22 Feb 2024 11:51:06 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rcxIf-00005g-4V; Thu, 22 Feb 2024 00:50:57 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rcxIX-000057-Kl for kernel-team@lists.ubuntu.com; Thu, 22 Feb 2024 00:50:49 +0000 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7635A3F636 for ; Thu, 22 Feb 2024 00:50:49 +0000 (UTC) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-1d7465d60b7so55314595ad.3 for ; Wed, 21 Feb 2024 16:50:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708563048; x=1709167848; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iJUd1S1XLbg08csZ4cCDbsVcSa8D7tC3Zcn/VyTrU8o=; b=pajBBeAJHPz3duVyrReHJUmpeUTDId+SmR+tgT6LvINA1pEZ0vNwM8Sg2JgiRna3Tl SGRqJ3NXGnzwCWikjLWy2HYa6yvlN/h7f6NA5upW3cjO8wA3ruN0u6GUAVE7CI/7W/gc B63xMPS1eci2uZbku4nRK8+66AeyztkVsHL+efYViy46c8xUe/iPYa77R+HXpJa5V/HS ZpbTaeiEv5CT7w2bDYufdBxBV32nuFmdrHH8Kcy1EQL5mIQsq+NkLto3Wp+Hy+6FKkXo r/y0013jTPc0il4vfCWS8cG0RTHxJWYP9TOw4ryuNaNl/ZCNHMiY84HH3B9c/hxSmnPa Ab/Q== X-Gm-Message-State: AOJu0Yw4FdKe3ENHLydOeXhLBlg1XiqAnMUEveMEWvTBlqvFnkAodWEG 2wyLjlG9ErD25EiQA6cHi43EFaqVrpvv+qq6Gd8K2bTWVaEbku/m7ZSILDxfOEzr9dxu6Hiffz7 ajaZvMmrAa7A3Z1NRLBd2z16h+JkRmKNar6xMexlitdNMJkbA7Jl0S43b8T3+0Yl0mXEgVhr2dm Urc4Firb/PAw== X-Received: by 2002:a17:903:41c8:b0:1db:e3e0:4d36 with SMTP id u8-20020a17090341c800b001dbe3e04d36mr13361664ple.43.1708563048067; Wed, 21 Feb 2024 16:50:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFt6/GJASFVKJsIFYXOW2nMKwEvuKwayPA+NjvfK0uoPscfFZ5G2L9qz7PxXKy2MAUTT4zIww== X-Received: by 2002:a17:903:41c8:b0:1db:e3e0:4d36 with SMTP id u8-20020a17090341c800b001dbe3e04d36mr13361652ple.43.1708563047684; Wed, 21 Feb 2024 16:50:47 -0800 (PST) Received: from ThinkPad-X1.. (222-154-76-179-fibre.sparkbb.co.nz. [222.154.76.179]) by smtp.gmail.com with ESMTPSA id km14-20020a17090327ce00b001db535f1549sm8643820plb.235.2024.02.21.16.50.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 16:50:47 -0800 (PST) From: Matthew Ruffell To: kernel-team@lists.ubuntu.com Subject: [SRU][Mantic][PATCH 1/1] smb: Fix regression in writes when non-standard maximum write size negotiated Date: Thu, 22 Feb 2024 13:50:39 +1300 Message-Id: <20240222005039.15585-2-matthew.ruffell@canonical.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240222005039.15585-1-matthew.ruffell@canonical.com> References: <20240222005039.15585-1-matthew.ruffell@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Steve French BugLink: https://bugs.launchpad.net/bugs/2049634 The conversion to netfs in the 6.3 kernel caused a regression when maximum write size is set by the server to an unexpected value which is not a multiple of 4096 (similarly if the user overrides the maximum write size by setting mount parm "wsize", but sets it to a value that is not a multiple of 4096). When negotiated write size is not a multiple of 4096 the netfs code can skip the end of the final page when doing large sequential writes, causing data corruption. This section of code is being rewritten/removed due to a large netfs change, but until that point (ie for the 6.3 kernel until now) we can not support non-standard maximum write sizes. Add a warning if a user specifies a wsize on mount that is not a multiple of 4096 (and round down), also add a change where we round down the maximum write size if the server negotiates a value that is not a multiple of 4096 (we also have to check to make sure that we do not round it down to zero). Reported-by: R. Diez" Fixes: d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather than a page list") Suggested-by: Ronnie Sahlberg Acked-by: Ronnie Sahlberg Tested-by: Matthew Ruffell Reviewed-by: Shyam Prasad N Cc: stable@vger.kernel.org # v6.3+ Cc: David Howells Signed-off-by: Steve French (cherry picked from commit 4860abb91f3d7fbaf8147d54782149bb1fc45892) Signed-off-by: Matthew Ruffell --- fs/smb/client/connect.c | 14 ++++++++++++-- fs/smb/client/fs_context.c | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index 6b5465d800ad..33abbc93ded8 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -3402,8 +3402,18 @@ int cifs_mount_get_tcon(struct cifs_mount_ctx *mnt_ctx) * the user on mount */ if ((cifs_sb->ctx->wsize == 0) || - (cifs_sb->ctx->wsize > server->ops->negotiate_wsize(tcon, ctx))) - cifs_sb->ctx->wsize = server->ops->negotiate_wsize(tcon, ctx); + (cifs_sb->ctx->wsize > server->ops->negotiate_wsize(tcon, ctx))) { + cifs_sb->ctx->wsize = + round_down(server->ops->negotiate_wsize(tcon, ctx), PAGE_SIZE); + /* + * in the very unlikely event that the server sent a max write size under PAGE_SIZE, + * (which would get rounded down to 0) then reset wsize to absolute minimum eg 4096 + */ + if (cifs_sb->ctx->wsize == 0) { + cifs_sb->ctx->wsize = PAGE_SIZE; + cifs_dbg(VFS, "wsize too small, reset to minimum ie PAGE_SIZE, usually 4096\n"); + } + } if ((cifs_sb->ctx->rsize == 0) || (cifs_sb->ctx->rsize > server->ops->negotiate_rsize(tcon, ctx))) cifs_sb->ctx->rsize = server->ops->negotiate_rsize(tcon, ctx); diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c index a3493da12ad1..75f2c8734ff5 100644 --- a/fs/smb/client/fs_context.c +++ b/fs/smb/client/fs_context.c @@ -1107,6 +1107,17 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, case Opt_wsize: ctx->wsize = result.uint_32; ctx->got_wsize = true; + if (ctx->wsize % PAGE_SIZE != 0) { + ctx->wsize = round_down(ctx->wsize, PAGE_SIZE); + if (ctx->wsize == 0) { + ctx->wsize = PAGE_SIZE; + cifs_dbg(VFS, "wsize too small, reset to minimum %ld\n", PAGE_SIZE); + } else { + cifs_dbg(VFS, + "wsize rounded down to %d to multiple of PAGE_SIZE %ld\n", + ctx->wsize, PAGE_SIZE); + } + } break; case Opt_acregmax: ctx->acregmax = HZ * result.uint_32;