From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE1183BE14B for ; Wed, 4 Mar 2026 14:05:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772633122; cv=none; b=LgFYeRJV3xmbgrE5K64En+XpCM494paM2TA/oHyvLXdkBm61rM7d6OInqkNpLlSVYUsg+BDhN8E2l6ipyFxb3RLzUsRjOQfV23ovH+j/tBGfYAn1EiFv4Lzqqj/RQdz8l22DB0vU39OwuWtGpifXUfNW9RRktzYKiCSz95aJoTM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772633122; c=relaxed/simple; bh=BW/nCNQi/Wwtq8VceluTVWZMpfy1RTkmPNQfQ4CSMX4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Zy5ZepkhcAKijZjNya3uluurhcYiES5oIJSvgV3ksYlEvFM8wlRsCqGw3EL9BY81okSuWPAxwFxWe8xFUu1sZIsQPig97BRJGU4xfURf4jLG/KIoyzWOCmiGdZ6wFNcIMH6Sq/UFoqLbweIXhe6fpNwOvbE9vcTTiDNwii1z3KI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TLCiZyQh; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TLCiZyQh" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-35994d84c6dso1223148a91.2 for ; Wed, 04 Mar 2026 06:05:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772633120; x=1773237920; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Drhy/JUcroGEZ7sou8Wymaklx4bBsa8tDfSu0E7JSNU=; b=TLCiZyQh6289c3qBuapXJreiC0O7/FJq9loLu+GA11pE/4BpFybdYYdmg5cQS3K9bE bsI5Wxl9LNyAYFvkLxBWcdXzdSpbUy5AHaFxkX1kWIqfTrv6y0Bj5RH5ShtLWiFNP1UF iGY4ag/es4PoyjApHyiVXHBtJvT8MYYEOHdznVAImlsQ2bo8L9iD2XwFRc4BD8euMO+U UkKAWyKw3n10ve1VrPmiIKguuJDUoL3WI+/2jPng2rKRkuE3oxDEXZ2Pq5i3TQSyLgUw LovtbUoLvuFFaxH+R6tGwWXWYOGLKBjGVVVDdnw+3d8Rvung3bPhACSnthe3CgNpL9tM PtOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772633120; x=1773237920; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Drhy/JUcroGEZ7sou8Wymaklx4bBsa8tDfSu0E7JSNU=; b=lYawSixEuZgAOfRFH520iELlDq/oUeRFEYnZMtK0vU5JyspCu8mbgqIQMWsxf01Sxm SUQR4JtFRh/b9mdyofs5LVpY9abQRepz2FccZqFVnVa/Ju47FQV0ODst3efzhkfoJJlO uBU4+wCylOa8yLdQkjJnNH07m19lVgtG7yS5D3peoNZaft2bVP5QUuhr0jckVtfvX0dA w6m0rs9j/sw1vhH081RWQfNJUFZzyefE3sYHrU63VsEk1KrybE71y+0hE9JnI5cG2LAJ y4F4D1J2fjFFhByA/z4ghu58hTNNJ8VM8EpJc6vMtGV4Q37p2LwEk2YbzlmAdahJwbib LAJA== X-Forwarded-Encrypted: i=1; AJvYcCVOKPc/wwS0Q10HXdetROrz1fc/KE48on8TcODw9DyZakRlLQmop75Mo4gLxNN7nOspqL4DvYU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9+dOJ+jOHm93zGlyTYkM+xwuQOPLaBNQdX1OxLB6FcWiSfCFh 1W0NUvwsb6kF68eW3OKu7wexCQrdZKxZeKTCCc5amlAfH4orRjJPoTem X-Gm-Gg: ATEYQzy+Fno0Skchu18Lqhdvl2vN/JH88lpLD2QWd90b8Yks33DnEB/bybzTmGhYGQh t5xxwrLAN5VDvyBeI+2hYKfCxcdE/y59qD6UEMUS9/MpNMcDLUVl69i/SZZev3wU8p4RU26EOTA frIrEgJSgvVWTTI4oXKoVT0H/B+QNYPsSxA5QLt2p5VOHGP6NS31qenxhljy9CoLa9e9of6uhYF IJEHKXFp9d5ux1N5s+1LZAU+3zhxgfW4E5n70s9spwkdTF6zC8HN/6YURE3gNGpZz+KTAKb5Dc0 IquVGpt7ZoKaduoU3vsO782m8OEFMGTUKlX7OOiVfG8az+sXHX53Xr3Fl5SvUAMLaCxPA+bVI9z a2r1aYxnXVGRfMvkMZlJ+Fz9dl4IeIfy46LWcgDmjjAyNQyGUUhb9GgSAE572no7IO57Jcn+Jyu jEcqorg87oMU94+tMAJ+ZQ7R0rhx9EcyowrgdDTFSIctLLW4nKgA== X-Received: by 2002:a17:90b:3d50:b0:340:be44:dd0b with SMTP id 98e67ed59e1d1-359a6a7bcb5mr2156907a91.34.1772633120193; Wed, 04 Mar 2026 06:05:20 -0800 (PST) Received: from bharathsm-Virtual-Machine.. ([167.220.110.53]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-359aa40c1bbsm451953a91.14.2026.03.04.06.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 06:05:19 -0800 (PST) From: Bharath SM X-Google-Original-From: Bharath SM To: linux-cifs@vger.kernel.org, smfrench@gmail.com, dhowells@redhat.com, sprasad@microsoft.com, pc@manguebit.com, ematsumiya@suse.de, henrique.carvalho@suse.com, bharathsm@microsoft.com, stable@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.6.y] smb: client: fix page cache corruption from in-place encryption in SMB2_write Date: Wed, 4 Mar 2026 19:34:52 +0530 Message-ID: <20260304140452.1606662-1-bharathsm@microsoft.com> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit SMB2_write() passes data kvecs inline in rq_iov by setting rqst.rq_nvec = n_vec + 1. When SMB3 encryption is negotiated, smb3_init_transform_rq() -> crypt_message() encrypts data in the kvec buffers in-place. For synchronous writes through cifs_write(), the kvec buffers point directly into the page cache via kmap(). In-place encryption overwrites the page cache with ciphertext. If the send fails with a replayable error such as -EAGAIN (e.g., from a connection reset), SMB2_write() retries the write using the same iov[1] buffer. Since iov[1] now contains ciphertext from the first attempt, the retry encrypts and sends ciphertext-as-data to the server, resulting in data corruption. The corruption is most likely to be observed when connections are unstable, as reconnects trigger write retries that re-send the already-encrypted page cache data. The sync path can be reached during partial-page O_WRONLY writes when the page is not in cache (common for append workloads with repeated open/write/close patterns). The async write path (smb2_async_writev) is not affected because it passes data via rqst.rq_iter, which the encryption layer handles without modifying the source buffers. Fix by setting rq_nvec = 1 (header only) and moving data kvecs into rq_iter via iov_iter_kvec(). Signed-off-by: Bharath SM Reviewed-by: Shyam Prasad N Cc: stable@vger.kernel.org --- fs/smb/client/smb2pdu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index a8890ae21714..a88a19dec494 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -5072,7 +5072,11 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, memset(&rqst, 0, sizeof(struct smb_rqst)); rqst.rq_iov = iov; - rqst.rq_nvec = n_vec + 1; + rqst.rq_nvec = 1; + iov_iter_kvec(&rqst.rq_iter, ITER_SOURCE, &iov[1], n_vec, + io_parms->length); + rqst.rq_iter_size = io_parms->length; + if (retries) smb2_set_replay(server, &rqst); -- 2.45.4