From patchwork Mon Nov 18 15:35:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Alcantara X-Patchwork-Id: 13878797 Received: from mx.manguebit.com (mx.manguebit.com [167.235.159.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89B4E1AA1E7 for ; Mon, 18 Nov 2024 15:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=167.235.159.17 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731944137; cv=fail; b=lvv7KwIHmEncy7lydQ7qrROT5vJ/5ES9fFnI8bus/fItEjqxXBbd9LPC4W5gDWdGY42ZLoUcn7sJmrFtzJynNgwlaCpC5RRYyBwRl9LtGmt9SLnbJ0XVXTIhUDq8l1Lvv2xFeJaPRq6v2euYkZLDohRMEhOeh8zxW+4jTGMqcTM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731944137; c=relaxed/simple; bh=/cvGHfH+cXkkL4flPpiqhwVaQLZ4ZD8N9U0fCwaIrwI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Z+sMUwh4irgTlJVo2x8HfNoZujt7Fk0wR/2u3qnnRX7DVu9muIn+exLcFUN93Gdcs8+V1E1XnTidoDtnXwyTBwNemJdsc4ayfx8dNocr0K8K17ZVo7DRG2B7nOQkegZk3/ixkN/mt0aw8toSJx01puHvOUvONNRqi+AzH2oDphA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.com; spf=pass smtp.mailfrom=manguebit.com; dkim=pass (2048-bit key) header.d=manguebit.com header.i=@manguebit.com header.b=p26/wKXH; arc=fail smtp.client-ip=167.235.159.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manguebit.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manguebit.com header.i=@manguebit.com header.b="p26/wKXH" From: Paulo Alcantara DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manguebit.com; s=dkim; t=1731944126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hgEWU/l9kTKR00Wg5h+h9LaaAzkqYSZi84Dy671GQfE=; b=p26/wKXHOvPzO5x1Phg+YvCsA4xNAZzz7zL8qF3CV1kVssx2aZ33uKPD7BEzrapiw2PrFO XBzkKRKF8f+os4A+QfPgJzDgNKieMdugGaD+UuzfApt1hR9bJrlp0L5FAbRBNHuLQj80rb tkSITLlPJ5VHvGdl+MyN/a7DqvMF6y6ZtReiWO4mSFttZ3z0IgTtXsU5YwKGC5RAd9b3f5 P9qIR147WmuMFTKRRwIQ0wbJHeVKDjGX84QFgb9hYUQ2DTR5j0O836jQh/HWcc4jg6gtUN nb2/a5P6HjpfQptZj8OBcJOsIB/btS8x9znVRHVqgm04HUjd/Bp0EUHHcAXagg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=manguebit.com; s=dkim; t=1731944126; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=hgEWU/l9kTKR00Wg5h+h9LaaAzkqYSZi84Dy671GQfE=; b=khFtSvkGNXtdnN6TAXL8chSBAEByBl5PnMMLIlZAcnvtYAftip0EehfdTGH+cr3iEk0m1p vPntjh7UW7WvfWgYtBxnuaBZ+0rdjvGBDQFZpk9ZRsTYG4F98UJ96Ld+iWmlV9pWHGtnmr ZWppSARZALw0zMnZYpu3U3POJGfpjsqP4TtIoIj1q66c5e/IOdIkTpK2JWkPwc7G0N5wkt CwghsSw2N0bg+256ETYQHsp8qUYDU5r9AX7YRAlNCeefOOVm819+TtP7HDRZYVyfSn6yY2 c5hR1tBZuHKDaBmVq9YUhPciS914/c+FpBM6c3SYKhrH+3aIXfyJuSesz9/+4Q== ARC-Seal: i=1; s=dkim; d=manguebit.com; t=1731944126; a=rsa-sha256; cv=none; b=AFqpZ4l+iPEAFNjoFaT95lGh9o46Yn3YmCCuszhuBNdkt0GJm9SK7PjPr4nxfd5GHwiGay 7oG3RkT+fB+cqv62Ou1aGoxEJ3a5enbJixy9ZLpfHabhmsLAdUdqH97mXA71QlOt7CX1Ym juTwX0/EuGJrPi2yXjwoWs4WhgIYe5d64aA4F1x6aD2fhAaA9rGWUmhkqM18TgyK8G+35X NbgyBSzge5UyOg30wIPjLxoHQDVXJacSiCxi1hYB2zOgK0icsryvmolWtDyWmZ9Ya6Wrun q7NzV4UWtHI1hgaM70MGyhMvC4yR91GE4zCP7MYFGX5RrsVBbHc+lm57n6QrJQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.mailfrom=pc@manguebit.com To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, Paulo Alcantara , David Howells Subject: [PATCH 1/3] smb: client: improve compound padding in encryption Date: Mon, 18 Nov 2024 12:35:14 -0300 Message-ID: <20241118153516.48676-1-pc@manguebit.com> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 After commit f7f291e14dde ("cifs: fix oops during encryption"), the encryption layer can handle vmalloc'd buffers as well as kmalloc'd buffers, so there is no need to inefficiently squash request iovs into a single one to handle padding in compound requests. Cc: David Howells Signed-off-by: Paulo Alcantara (Red Hat) --- fs/smb/client/cifsglob.h | 4 ++-- fs/smb/client/smb2ops.c | 37 +++--------------------------------- fs/smb/client/transport.c | 40 +++++++++++++-------------------------- 3 files changed, 18 insertions(+), 63 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 63d194ebbd7d..fc33dfe7e925 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -2230,7 +2230,7 @@ static inline int cifs_get_num_sgs(const struct smb_rqst *rqst, struct kvec *iov = &rqst[i].rq_iov[j]; addr = (unsigned long)iov->iov_base + skip; - if (unlikely(is_vmalloc_addr((void *)addr))) { + if (is_vmalloc_or_module_addr((void *)addr)) { len = iov->iov_len - skip; nents += DIV_ROUND_UP(offset_in_page(addr) + len, PAGE_SIZE); @@ -2257,7 +2257,7 @@ static inline void cifs_sg_set_buf(struct sg_table *sgtable, unsigned int off = offset_in_page(addr); addr &= PAGE_MASK; - if (unlikely(is_vmalloc_addr((void *)addr))) { + if (is_vmalloc_or_module_addr((void *)addr)) { do { unsigned int len = min_t(unsigned int, buflen, PAGE_SIZE - off); diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 24a2aa04a108..6c4a7335a8a2 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -2606,7 +2606,7 @@ smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst) struct cifs_ses *ses = tcon->ses; struct TCP_Server_Info *server = ses->server; unsigned long len = smb_rqst_len(server, rqst); - int i, num_padding; + int num_padding; shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base); if (shdr == NULL) { @@ -2615,44 +2615,13 @@ smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst) } /* SMB headers in a compound are 8 byte aligned. */ - - /* No padding needed */ - if (!(len & 7)) - goto finished; - - num_padding = 8 - (len & 7); - if (!smb3_encryption_required(tcon)) { - /* - * If we do not have encryption then we can just add an extra - * iov for the padding. - */ + if (!IS_ALIGNED(len, 8)) { + num_padding = 8 - (len & 7); rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding; rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding; rqst->rq_nvec++; len += num_padding; - } else { - /* - * We can not add a small padding iov for the encryption case - * because the encryption framework can not handle the padding - * iovs. - * We have to flatten this into a single buffer and add - * the padding to it. - */ - for (i = 1; i < rqst->rq_nvec; i++) { - memcpy(rqst->rq_iov[0].iov_base + - rqst->rq_iov[0].iov_len, - rqst->rq_iov[i].iov_base, - rqst->rq_iov[i].iov_len); - rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len; - } - memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len, - 0, num_padding); - rqst->rq_iov[0].iov_len += num_padding; - len += num_padding; - rqst->rq_nvec = 1; } - - finished: shdr->NextCommand = cpu_to_le32(len); } diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c index 91812150186c..0dc80959ce48 100644 --- a/fs/smb/client/transport.c +++ b/fs/smb/client/transport.c @@ -418,19 +418,16 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, return rc; } -struct send_req_vars { - struct smb2_transform_hdr tr_hdr; - struct smb_rqst rqst[MAX_COMPOUND]; - struct kvec iov; -}; - static int smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, struct smb_rqst *rqst, int flags) { - struct send_req_vars *vars; - struct smb_rqst *cur_rqst; - struct kvec *iov; + struct smb2_transform_hdr tr_hdr; + struct smb_rqst new_rqst[MAX_COMPOUND] = {}; + struct kvec iov = { + .iov_base = &tr_hdr, + .iov_len = sizeof(tr_hdr), + }; int rc; if (flags & CIFS_COMPRESS_REQ) @@ -447,26 +444,15 @@ smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, return -EIO; } - vars = kzalloc(sizeof(*vars), GFP_NOFS); - if (!vars) - return -ENOMEM; - cur_rqst = vars->rqst; - iov = &vars->iov; - - iov->iov_base = &vars->tr_hdr; - iov->iov_len = sizeof(vars->tr_hdr); - cur_rqst[0].rq_iov = iov; - cur_rqst[0].rq_nvec = 1; + new_rqst[0].rq_iov = &iov; + new_rqst[0].rq_nvec = 1; rc = server->ops->init_transform_rq(server, num_rqst + 1, - &cur_rqst[0], rqst); - if (rc) - goto out; - - rc = __smb_send_rqst(server, num_rqst + 1, &cur_rqst[0]); - smb3_free_compound_rqst(num_rqst, &cur_rqst[1]); -out: - kfree(vars); + new_rqst, rqst); + if (!rc) { + rc = __smb_send_rqst(server, num_rqst + 1, new_rqst); + smb3_free_compound_rqst(num_rqst, &new_rqst[1]); + } return rc; } From patchwork Mon Nov 18 15:35:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Alcantara X-Patchwork-Id: 13878796 Received: from mx.manguebit.com (mx.manguebit.com [167.235.159.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89AEA1A9B3D for ; Mon, 18 Nov 2024 15:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=167.235.159.17 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731944137; cv=fail; b=leOw/w9l4bnBHiFyhZxFdPit/WGgI24YRrHho37SvzLl1dvUKAKqosR5i0Gpn/CIrFLBvoPg/XnWb4U0LSYEywxyD6bcuUbjk9VPjt/ET5DHfizuN3N5C6dE90DQqmTv32h4p8FXI6XeCT6cNEcdVuVdUyiz6UWpid2GfyI7acE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731944137; c=relaxed/simple; bh=kGcFdY3Qu4Hcsn9vtxOKyGMkC/GDtzYB1kMLNM3u/1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tMCrLfMs+DWsdH+d7VJTyUEmZC6H45UqZP5waAysvOTqkhBQPkVdWUa1C3R+jTREF5PrMBrg9i311b5l3H3D+bStQGMojQu7Da1nFB72PV6t+FbCglPNGimGl+pDUnLVyjkw7eDQF7neXMh/NacsA6qTC1JN19V0nwafI/6iYJY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.com; spf=pass smtp.mailfrom=manguebit.com; dkim=pass (2048-bit key) header.d=manguebit.com header.i=@manguebit.com header.b=c2AQmKtQ; arc=fail smtp.client-ip=167.235.159.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manguebit.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manguebit.com header.i=@manguebit.com header.b="c2AQmKtQ" From: Paulo Alcantara DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manguebit.com; s=dkim; t=1731944128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z6bYezLH9HEYp9M1Lfk9fsTUlHhVC0887Oi8oZJdkyM=; b=c2AQmKtQqPHOZ27noNCbkPYxdvR//i0tUSus3My8hOK106LUgbRGXcQL2+D3+lmOa8md3q eLvJNNaduSUHiWaZ1czqdYHlc2pUqzwyXxsVLMMxkbuN3ZqT+LWJqq/OGcJnlzr66AW8po o03XlOCJqfflo74QFZ72NgrOYkRsgorWquLQuPhPgj2EORR4fNocy5ONhSgCFUT0jEQUFa UH8IBSBLYtrrl6FTzKiPsdsgnoLSOCoq8LnSK/ZwdIgynw4abInfe1ggPyEaLxNIoXeI1q eilFhbPrciyxwbSN8lqXutA6D/cGS0AbXzeR+F0UKo9nszh0s8GWQ5MdMETqXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=manguebit.com; s=dkim; t=1731944128; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z6bYezLH9HEYp9M1Lfk9fsTUlHhVC0887Oi8oZJdkyM=; b=GkdF6fwuFse7Zyo8+IHb6mw1eKvp452mNZkyaCsIZzSIMBCGBTcoXRvq+eBxVSsTD/MC7S PZvOw5ahekYBo7UCwlogcdLUjzh4JwrCPC0r4ars68f3nomCAqke6D2RUVfuz/0H+9+JTK JoIZzE3K8Fnd9zRpKlPPaFHztt12wHkSfBcdvPbhH6wmvZ3F4JipQ5kh3RX2TMVRLSQfDk /Lk6LikALzpFIHRcUDkEWY4+her7dwtSJOmTM1G1YtZtg8u2J/affbPbuULkHQN9pCJtpL 0nOxPHz3zuvKG+o6kUm0aZ3sYYKJmwUOANg2aNDLLFe5rwIh6wQHBs5oYm0r1g== ARC-Seal: i=1; s=dkim; d=manguebit.com; t=1731944128; a=rsa-sha256; cv=none; b=of47eJELfPuezg8taXt9UcXhJJ10Bld+FXFnMvALimbdGMh4eS3hzhAxtFeLUPaUl43rFX Y8Fzt05wdmKmXqzpYF74dGXLauXR3SS3LSx268QmcoMThCYnyoXfhHzU+r/N5nFiducchw PpQrdrXmgmvG3JlorlJAerr3yMuskpWTfoDBch258UmyVCoQLJob8MeF9ZZlyhFBm+iAE0 4DGAIX4FNmp+TPYXFciVHD83wTAeaBlcg6FwRocL2bmz3CX5cHv5jQnNSNoL3u5AJGtkq9 f8vYVIjZ+LL8X+mDcxRBSlvyjCDnSXxUMqFdLpA16dhlg+9OrMnlMrxxsl0iWA== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.mailfrom=pc@manguebit.com To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, Paulo Alcantara , David Howells Subject: [PATCH 2/3] smb: client: get rid of bounds check in SMB2_ioctl_init() Date: Mon, 18 Nov 2024 12:35:15 -0300 Message-ID: <20241118153516.48676-2-pc@manguebit.com> In-Reply-To: <20241118153516.48676-1-pc@manguebit.com> References: <20241118153516.48676-1-pc@manguebit.com> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 smb2_set_next_command() no longer squashes request iovs into a single iov, so the bounds check can be dropped. Cc: David Howells Signed-off-by: Paulo Alcantara (Red Hat) --- fs/smb/client/smb2pdu.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index ab3a2ca66be3..055236835537 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -3313,15 +3313,6 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, return rc; if (indatalen) { - unsigned int len; - - if (WARN_ON_ONCE(smb3_encryption_required(tcon) && - (check_add_overflow(total_len - 1, - ALIGN(indatalen, 8), &len) || - len > MAX_CIFS_SMALL_BUFFER_SIZE))) { - cifs_small_buf_release(req); - return -EIO; - } /* * indatalen is usually small at a couple of bytes max, so * just allocate through generic pool From patchwork Mon Nov 18 15:35:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Alcantara X-Patchwork-Id: 13878798 Received: from mx.manguebit.com (mx.manguebit.com [167.235.159.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29E751AA1E7 for ; Mon, 18 Nov 2024 15:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=167.235.159.17 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731944141; cv=fail; b=MrrDOQ0V6mQVcKs6GVmz0SG4vnyWam/K73CV5bQPb4A9RHARlyeZsET7pmR7hp1CzfX7yNOETErx51ZS9XpmP/6bv8FovX+OZSdrVeYa25l7UQT0ZZIc0Nb1bNWFH2R5xKCgZXFKD6PG1n2jxLiB/c8Qqo5dCtArwt5MItRrtts= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731944141; c=relaxed/simple; bh=KioX2BUz5l1UgYKt068YvXnO6NEjPm5yK/pokJh/Bfk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ocpYWPMNkJEJgajl+eT3lGJ+9T+Yl1MDIjQHWgBIM4ldty8Lw4MOc0Q19IKCa5toi13YGOOSROY2WtivXwdOB5nK1HyP2mJEURGnxS2+IOmXlEZcZ5UQySB1Jey1Cq63CpyYJeSoA6VvXWp/tzj9tlvSmNy6DOANessMypEAn5E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.com; spf=pass smtp.mailfrom=manguebit.com; dkim=pass (2048-bit key) header.d=manguebit.com header.i=@manguebit.com header.b=V5iHtbFX; arc=fail smtp.client-ip=167.235.159.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manguebit.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manguebit.com header.i=@manguebit.com header.b="V5iHtbFX" From: Paulo Alcantara DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manguebit.com; s=dkim; t=1731944129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pmAI3VN/eB0b4w2t7LMBHbJ0j2zGdpXDdSoTNmjs8CU=; b=V5iHtbFXLLxsjr+EqYBLseBCns2NLkbEqRdz2IlmtdUvI12/P7veYF9+iafQCp3pyEEbKA Mv5iIF0K0RwrpnFZSqN7FURs9TuAAzVffN7gFADFXP3GpwQ5+hjmQVQXj5gNyX0Vqj/ysj s2p26oiEtn2wiTBUeFy9cTGsITK00XooYYKor29wARYgodtPR2d0OdvstUlEM6XIIkfxDr NQUSXnmbOhlW0EqmwsJzppvR0u6rdX9TVNDMu/7n0af4zwB9P0+Qel46GwmeJXRTG8glEB VoMbOlUy3hGFXCbVMgFGiOmyTdjGgCxTYy+67/RiRZH4LY7lrtX+kSB0zZ0qZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=manguebit.com; s=dkim; t=1731944129; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pmAI3VN/eB0b4w2t7LMBHbJ0j2zGdpXDdSoTNmjs8CU=; b=Ctn8ncO+KatMQzwrAEVZkTOiwHpbY35EtTA8lVCbxCacuwVb46X+lc78UzNYFl7jKu65br js+P6VO/QFE+897ESvTzlCgfJhu+1U4eFQYe1Sm/v+DQeejX+Ytcm8YlDR5Vb4LsS68kiu +fiXiqlUApOcygvdA+PeFTf057KLXmhZpmQiXb8SWmt5C00c3uol9JZujq54FzP27ai52I AJQb0h9/ukj9d+D8fFEzTDYDyHAWhgCFvDO9KN9WV1OIu/mD2peEbXV4SUwpYm/eem1nkU dTd7A/0GiUS4Huoe+6HCoLaJ0Dfuv27EgQLhtD43w35teKpgJpKazK+JhcqAQA== ARC-Seal: i=1; s=dkim; d=manguebit.com; t=1731944129; a=rsa-sha256; cv=none; b=K0HSsNArQHE3jMMBD4u5TRhRqG7dZF9o7LGF0WKIM0Fp9xj1+1MTFT4b8bvHQUjrsdKG7t YULfL1HY5T97ALBLXN0u7A8/A91tIb3KT/TDC8ocnIu/UNMvtuwCse84ZpqpH9iBEPdm7L 5p05sDeybBjVZFEIJdNnZcKlhSQ9Ic8VlbejJL6XR6K2ZCDuSgT+4I/cunv0VJCZ52/Li1 DEtpFOx+W0YLXrGJ3UvNDZt9WSU/c1ZQkorjoZxDZyBaYnwkCgQnQO1BulDQYQfDkN3LH9 JAcIpYDBZ8TiKUlS0caq98qcngO9RDmV79BXfYDN/dQ5FhWUapgQzWuR82gnPQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.mailfrom=pc@manguebit.com To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, Paulo Alcantara , David Howells Subject: [PATCH 3/3] smb: client: handle max length for SMB symlinks Date: Mon, 18 Nov 2024 12:35:16 -0300 Message-ID: <20241118153516.48676-3-pc@manguebit.com> In-Reply-To: <20241118153516.48676-1-pc@manguebit.com> References: <20241118153516.48676-1-pc@manguebit.com> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We can't use PATH_MAX for SMB symlinks because (1) Windows Server will fail FSCTL_SET_REPARSE_POINT with STATUS_IO_REPARSE_DATA_INVALID when input buffer is larger than 16K, as specified in MS-FSA 2.1.5.10.37. (2) The client won't be able to parse large SMB responses that includes SMB symlink path within SMB2_CREATE or SMB2_IOCTL responses. Fix this by defining a maximum length value (4060) for SMB symlinks that both client and server can handle. Cc: David Howells Signed-off-by: Paulo Alcantara (Red Hat) --- fs/smb/client/reparse.c | 5 ++++- fs/smb/client/reparse.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 74abbdf5026c..90da1e2b6217 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -35,6 +35,9 @@ int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode, u16 len, plen; int rc = 0; + if (strlen(symname) > REPARSE_SYM_PATH_MAX) + return -ENAMETOOLONG; + sym = kstrdup(symname, GFP_KERNEL); if (!sym) return -ENOMEM; @@ -64,7 +67,7 @@ int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode, if (rc < 0) goto out; - plen = 2 * UniStrnlen((wchar_t *)path, PATH_MAX); + plen = 2 * UniStrnlen((wchar_t *)path, REPARSE_SYM_PATH_MAX); len = sizeof(*buf) + plen * 2; buf = kzalloc(len, GFP_KERNEL); if (!buf) { diff --git a/fs/smb/client/reparse.h b/fs/smb/client/reparse.h index 158e7b7aae64..2a9f4f9f79de 100644 --- a/fs/smb/client/reparse.h +++ b/fs/smb/client/reparse.h @@ -12,6 +12,8 @@ #include "fs_context.h" #include "cifsglob.h" +#define REPARSE_SYM_PATH_MAX 4060 + /* * Used only by cifs.ko to ignore reparse points from files when client or * server doesn't support FSCTL_GET_REPARSE_POINT.