Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp31645355rwd; Fri, 7 Jul 2023 02:18:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlGroo4x4LxtXIRLdQwf7DY4Ic0IwILC+fdJVfUa5tJqK/Pgl8++Qc1jIvSYl3QqbA5ANYRq X-Received: by 2002:a05:6e02:1d0c:b0:345:a3de:20 with SMTP id i12-20020a056e021d0c00b00345a3de0020mr6954643ila.1.1688721484495; Fri, 07 Jul 2023 02:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688721484; cv=none; d=google.com; s=arc-20160816; b=1H89bGY1KYUKiHm7cXScfSvj+UIZQTQnsrEzX35DR+Jut4v+KL9jH+fb5v1OpeL0yD P0yGIDI3xOSqCTTBPyK0xO2pQO8GQnUK+TgELJNtq1fKhMHolSL6sqERjk+RiFEDcExJ 0LKNgYNRkXF6bDG8YqZh4cl3ezcAqSQZb2mGi9wSZei3iWcIbo0ojOUQticcyw1YPbNs fq11fH2JEmy+YqwabxrLncF+17mZqaRo6Lb3rYJcqA2hTKvycyTbjYBpm1umlVCCBAcm qVyANPIEW7+qjEH/i1uw4SfdshslzW7v7jnzne6UzQ+nF6lZOI9asYquHupGY9Ohrv53 YfhA== 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=wU3D20g/JxtCROQUSiRgjpayIvu8cn+paX5zco5nOco=; fh=rj9rFGOLEY+NU6XqvIWq5warMJ0dLuyf9oSN2aniU/M=; b=pST7PhBfhTjrE7AVvEsY9qVA9NfH9Gi0DIHgWYdvPBET4eKSa0D9Sr8zJfvKGAVrxv t8kd3aBaGn5sGO2/vz13YC/O8AK+78pMldTgy0KNHuVu9A3W0U2MjUPgwC8gF0v5c8hM 3jHJnBOJbyEfKf7bQFVUzx+PpKFD1jow5teyXyaHTOjWCCnIJs/+TPmYUEbJhLYxMTL1 cRokuK7CbuKyan+jN/VPqBZkmLjR714naK2NkxobivWPF44+cClkOrWv8m8UGXZXjKNL sGxfPufskX3AlmUKbu0RMnIUR9bXRFtbJdGj56Y2uGRGfyR8kCWyWchRVo4yEJ4xA5Aq GdcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bbWmP+qW; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 f10-20020a63de0a000000b005572b5c0f1fsi3459834pgg.369.2023.07.07.02.17.42; Fri, 07 Jul 2023 02:18:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=bbWmP+qW; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S232370AbjGGJNd (ORCPT + 99 others); Fri, 7 Jul 2023 05:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjGGJNc (ORCPT ); Fri, 7 Jul 2023 05:13:32 -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 9D5F21FF3 for ; Fri, 7 Jul 2023 02:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688721164; 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=wU3D20g/JxtCROQUSiRgjpayIvu8cn+paX5zco5nOco=; b=bbWmP+qWBgfZp0Aut9eT3/nhgbpVfKdKfQ54k0lTAAF7CM7WjQXD0EUqV70qI9BIXZGBfF a/uujDeqw8y8mXfYOjc1/oEkw0ZaDpkPwFFWr4wbKK1zKWmcX96kNbil7xsoYqVzlJmKZq Fn1uYsVybGWdQmrDJS9akSkYvTvbaUA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-136-aTE9Asg2OD6HYPoA1q_yrQ-1; Fri, 07 Jul 2023 05:12:41 -0400 X-MC-Unique: aTE9Asg2OD6HYPoA1q_yrQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C79483FC20; Fri, 7 Jul 2023 09:12:40 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DAD64067A00; Fri, 7 Jul 2023 09:12:39 +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: Herbert Xu cc: dhowells@redhat.com, syzbot , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jakub Kicinski , linux-crypto@vger.kernel.org, netdev@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] crypto: algif/hash: Fix race between MORE and non-MORE sends MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2227987.1688721158.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Fri, 07 Jul 2023 10:12:38 +0100 Message-ID: <2227988.1688721158@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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_H4,RCVD_IN_MSPIKE_WL,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-crypto@vger.kernel.org The 'MSG_MORE' state of the previous sendmsg() is fetched without the socket lock held, so two sendmsg calls can race. This can be seen with a large sendfile() as that now does a series of sendmsg() calls, and if a write() comes in on the same socket at an inopportune time, it can flip th= e state. Fix this by moving the fetch of ctx->more inside the socket lock. Fixes: c662b043cdca ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES") Reported-by: syzbot+689ec3afb1ef07b766b2@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/000000000000554b8205ffdea64e@google.com/ Signed-off-by: David Howells Tested-by: syzbot+689ec3afb1ef07b766b2@syzkaller.appspotmail.com cc: Herbert Xu cc: Paolo Abeni cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: linux-crypto@vger.kernel.org cc: netdev@vger.kernel.org --- crypto/algif_hash.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c index 0ab43e149f0e..82c44d4899b9 100644 --- a/crypto/algif_hash.c +++ b/crypto/algif_hash.c @@ -68,13 +68,15 @@ static int hash_sendmsg(struct socket *sock, struct ms= ghdr *msg, struct hash_ctx *ctx =3D ask->private; ssize_t copied =3D 0; size_t len, max_pages, npages; - bool continuing =3D ctx->more, need_init =3D false; + bool continuing, need_init =3D false; int err; = max_pages =3D min_t(size_t, ALG_MAX_PAGES, DIV_ROUND_UP(sk->sk_sndbuf, PAGE_SIZE)); = lock_sock(sk); + continuing =3D ctx->more; + if (!continuing) { /* Discard a previous request that wasn't marked MSG_MORE. */ hash_free_result(sk, ctx);