From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 5FAA481B37 for ; Wed, 18 Nov 2026 20:52:17 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIKou2N029126; Wed, 18 Nov 2026 23:50:57 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIKou2N029126 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="Paj3adOK" Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIKosYw029121 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 18 Nov 2026 23:50:54 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIKosYw029121 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48e0ef019a4so1153162f8f.3 for ; Wed, 18 Nov 2026 12:50:54 -0800 (PST) X-Gm-Message-State: APuU4Z8F8Ocy5cKuYrsNqXxK52wnpmCUFQZjruheCtyOSCMojRkeDUDc Xqfc2bMH5T2NhfKpTivGueFHzp5vdegWnAE+HYJcKlONDhcH4T8K7/8MrBZSBuLtwyFvduIJpEI /ZZzTR5xN+tdExTRQa68AEkR9WR3HZxmwOp/aIHxRXkqBr6o1SwRkvg== X-Gm-Gg: AZFdTZfZHnLJ9JEN4T4W8iXhoIB/bXxS7X2k05B1jqwliCM4m8Yvixl48JpQM2R2AZK yYaDn9UaQFQgdOwAuIQ6j0yDPnKR6KCPdOcJnNbI3r7PZPkaX8Tcm3OUebZf28bRn42Rsso4qfS k6ulSj4BwE/319Av74LSm250t8ESlcxDAqZJRCc05spLgKM5WloksA6H61ZDI+QRPmQXSFXY8p2 0cD20LEkWQnUn3dG7LbG0mHhkBFy1QRwE+GcFrDfF4RnFFvYDgM5l/3NhX9MqV51ei9g1nQyvIB BKbCIPbqEp1XJ6tL98y+UEnmLzAGAKBwZunMiQBUsmF9FA/Qsi6BecQLat0kMZxy0ol7NEvdNz1 IsV+LWisxcYaOcsZo X-Received: by 2002:a05:6000:402c:b0:4a6:2abb:c329 with SMTP id ffacd0b85a97d-4a6332bcbe4mr8661881f8f.2.1795035054364; Wed, 18 Nov 2026 12:50:54 -0800 (PST) X-Received: by 2002:a05:6000:402c:b0:4a6:2abb:c329 with SMTP id ffacd0b85a97d-4a6332bcbe4mr8661833f8f.2.1795035053741; Wed, 18 Nov 2026 12:50:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795035053; cv=none; d=google.com; s=arc-20260327; b=kNlRtDO7ZH62UXb/+TxUhmOGEJ4/tMSUL+/eu2bOyNyZ/cIu7B3WzkigyyCvNJNBCv EocBRY9VHFw8P5r+euhRU22XAU12v16OA2WMgRbsfSBCAd3urhTimKhza9Rr8tt0U5Hs FpuKzRRlQTy3+7LJCGFRee4onaqKJAOFV7QWNhPEqmz+dkEuSlmcHbCX/wbB0OPJKt2u loyqKnCBy7+YLu/3PPoSr866RFEPiwt5iAseydl71TG6kR6uGyXNNnsJZxGmS4aSdJxK bnCNtsxKgGfhEIvULLTjEalUzf8lb2lvHrpafSxuVmk1YhpfUHDjr2V/4jy4rdtbAvK7 NeqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:dkim-signature; bh=+DTKJCJcfgOJt5ifVUWPKvBCWW3cjO0f8TGu9DpZjFY=; fh=26FXTO6eY/S3gvyMXNKNKTFHQ0lD1bPkQ8wRpe0tMZI=; b=rslw/W680bIykYsdxailcSuOkmF70J1PghWr2yfeeF8SowAGgoDWlldIMKwdsv1bCK ohEdX+p61eZkM5RbhhRaVHQh7kg8/5boPYVbE+9DGhG0XUJ5M3RUG9Fh94Eb2jZKV5eP J3OxU8Y9G9pI+wLhclyTI4Ndr/Oc7013U4dZ9FLscaoyx6ILVc0p2MGm2Ac9qJHO01T1 ScGN+MjllPC4ijZ3mGjVRPXSYwCKZQkVym5J0AFWulO2yIeIBq1DoZQcDv2OEMcqDIC2 /Ufw6kSmgosKqVSkn3afUH89qjMWGtszmxt32MAvq3BHJcgqSaN7/3o7rxku+2wVELMF SnMg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Paj3adOK; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a65a0c5102si7091175f8f.347.2026.11.18.12.50.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 12:50:53 -0800 (PST) Received-SPF: pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Paj3adOK; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=+DTKJCJcfgOJt5ifVUWPKvBCWW3cjO0f8TGu9DpZjFY=; b=Paj3adOK7DKXiHef+Va T6Jh94Lb6/2ktu95cGNQ/vIx6qO0D8BH9esITuzDkY4SuXrqLqhr+LSC6+cVkjQCoqKjMk2IMmeU+ iGBYiVXlj7qSm1Oh22CiSHwveJLRzQXPAmXj9BPBL/CCFdl9VWxHBsZllzXtb47tz40huJF5cKuq7 i8ybK9uDpEvqxr4ro09pNkqG+wGyUIoarkCOGDhZt1pZHFHcvS+Ntlk94otrKIUmF7gkiQlSjMX0o CzqmyF9U7rmPWSnm5N5z1lm834nfKdlycHyZ7P4PE8dZ7CvxSriC2ZgpfwWR+7UEvr2+tyRoJxMDB PQeidri6hD+9MgA==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xTmXy-00DYTk-2J; Wed, 18 Nov 2026 21:50:52 +0100 From: Konstantin Khorenko Date: Wed, 18 Nov 2026 21:50:44 +0100 MIME-Version: 1.0 Message-Id: <20261118-b4-prep-khorenko-vstor-154198-af_alg-concurrent-writes-v1-1-786b51d5872d@virtuozzo.com> X-B4-Tracking: v=1; b=H4sIAKMP/moC/yWNUQ6CMBAFr0L2201axAJexRjTlgUqpiXbgkbC3 a36Oe8lMxtEYkcRzsUGTKuLLvgM8lCAHbUfCF2XGUpRKilFi6bCmWnGaQxMfgq4xhQY5amSbYO 6v+nHgDZ4u3D+Ez7ZJYpoyro5StUJpVvI8uzo3esXvsD6ruH6H+Ni7mTTNwn7/gEKVY58nwAAA A== X-Change-ID: 20261109-b4-prep-khorenko-vstor-154198-af_alg-concurrent-writes-b278316d06a9 To: Konstantin Khorenko X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3759; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=t1yrY1ewTp/gkLQHfGGsvkCYKVX+YszUG3m5in2+U68=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBq/g+s5tdL2SJq0qHDhMrC4cNWwfzvgB0VWM+Gk CQfeO7cs4mJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCav4PrAAKCRBRlgpH+WFc KlOxD/4+7BwTCxtKIwM+aKRKdyN9ecuYo06eCNhtRphWN+4YeBlnKoluY+/MWLr02E6ln8pLVZs CH0AKGTmiG77U6cHFy9N/IauAqy57BVBqUIuwSQvyy2zaEAa1kTlmLP3Fo7/WGIgWu4kroCfJ1h HoXob3YhleoRg7oaNKDjEOyQlSi8xQTJKw4H4Q+B/Yr5CLqKHTqeylqSSxZ2SRrFSgadinL3c1r fLFE4gUIeMmxyxY+ksmWaDJeiCtCzSmwA+wCkUB6U3zy36V4hWsbVIblY++AoQyFU9ZVlTFCdZw JwKIprMuBWxsm3fTitg+yZAiisTGj1oUNU7LdIN9g667DWuLJ6jXzZluY7sElrkczm1wVZJRCjk CWqDoA92o/fFR7LQC19wcAVStrbmbl5DAbPcieZcrxLO+9OkDrJH2eZxliqixtvwRnz+rhkR1Sk vNC/cEEiR6TukOKcPc5W6oi31zUKXJAM8zXqV8713hUY4AVuhTyEik4/51SM7uKNnNKGEMDP2L5 Y0DDeEwaKaThzUz9/mZSDJw5hv5wNX3uMFVz23O8A6GwQ0msXJfGTJjaAf27Wc2fM+gDi56xl79 FCQE5M3xPVML3+Dpnv2gspXdqKQZMq4yrHvan1y73t79V7IHps3bw9FF07A1DvbsVH6rxKlQold XPvUTmfusbSksIA== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH vz7] ms/crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Herbert Xu Issuing two writes to the same af_alg socket is bogus as the data will be interleaved in an unpredictable fashion. Furthermore, concurrent writes may create inconsistencies in the internal socket state. Disallow this by adding a new ctx->write field that indiciates exclusive ownership for writing. Fixes: 8ff590903d5 ("crypto: algif_skcipher - User-space interface for skcipher operations") Reported-by: Muhammad Alifa Ramdhan Reported-by: Bing-Jhong Billy Jheng Signed-off-by: Herbert Xu (cherry picked from commit 1b34cbbf4f011a121ef7b2d7d6e6920a036d5285) Backport notes: - the check goes to skcipher_sendmsg() in algif_skcipher.c; - write is a plain bool in struct skcipher_ctx, initialized in skcipher_accept_parent_nokey(). af_alg_sendmsg() and struct af_alg_ctx came with ms commit 2d97591ef43d ("crypto: af_alg - consolidation of duplicate code") in v4.14. Here each algif type still has its own sendmsg and context, and the code upstream consolidated into af_alg_sendmsg() is skcipher_sendmsg(). skcipher_sendmsg() drops the socket lock in skcipher_wait_for_wmem(). A second writer can then fill the tail sgl and set ctx->merge, while the first one appends an empty sgl and fails with EFAULT. The next write takes the merge path with sg = &sgl->sg[-1] and copies user data through a scatterlist built from the sgl header and the bytes before it. hash_sendmsg() and hash_sendpage() hold the lock for the whole write. skcipher_sendpage() only clears ctx->merge, so it is left as is, as 5.10.y left af_alg_sendpage(). The flags here are bool and the context is private to this file, so write is one more bool, not the 1-bit bitfield that ms commit d0ca0df179c4 ("crypto: af_alg - Fix incorrect boolean values in af_alg_ctx") had to turn back into bool. The context is not zeroed on allocation, hence the explicit initialization. RHEL7 kernel-3.10.0-1160.169.1.el7 has the same change in algif_skcipher.c. The closest stable backport is 5.10.y commit 0f28c4adbc4a: https://git.kernel.org/stable/c/0f28c4adbc4a97437874c9b669fd7958a8c6d6ce CVE-2025-39964 https://virtuozzo.atlassian.net/browse/VSTOR-154198 Signed-off-by: Konstantin Khorenko --- CVE-2025-39964 fix for the vz7 kernel. https://virtuozzo.atlassian.net/browse/VSTOR-154198 Assisted-by: LLM --- crypto/algif_skcipher.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index ad4a88628f959..703687d0d9604 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -50,6 +50,7 @@ struct skcipher_ctx { bool more; bool merge; bool enc; + bool write; struct ablkcipher_request req; }; @@ -284,6 +285,12 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock, err = -EINVAL; lock_sock(sk); + if (ctx->write) { + release_sock(sk); + return -EBUSY; + } + ctx->write = true; + if (!ctx->more && ctx->used) goto unlock; @@ -371,6 +378,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock, unlock: skcipher_data_wakeup(sk); + ctx->write = false; release_sock(sk); return copied ?: err; @@ -726,6 +734,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) ctx->more = 0; ctx->merge = 0; ctx->enc = 0; + ctx->write = 0; af_alg_init_completion(&ctx->completion); ask->private = ctx; --- base-commit: 78c10c447efc7633a8e4260fe7dc33e1cb4bb4d2 change-id: 20261109-b4-prep-khorenko-vstor-154198-af_alg-concurrent-writes-b278316d06a9 Best regards, -- Konstantin Khorenko, Virtuozzo Linux Kernel Team _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel