Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6634820rwd; Mon, 19 Jun 2023 09:56:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5MKctmxU//pEUSefQd8dZK/HIbPaxegREzc2KQe9Iecd9hyS2i2NoRBAlLn++xUxqb6FBe X-Received: by 2002:a17:902:dac6:b0:1ac:656f:a68d with SMTP id q6-20020a170902dac600b001ac656fa68dmr12626349plx.4.1687193810660; Mon, 19 Jun 2023 09:56:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687193810; cv=none; d=google.com; s=arc-20160816; b=LkX5o5eKLQTi7zpmkpkKNHhI+MYBMvVSpTJbPkci2h365dNeXvTq+W9n8EjGY9YTm0 IubbpJNrHeYO6jGZu+gTgOGCm8enmHBklLLnOfDu9Kwpz/pYRkfseBDtVa9BHaVuqzY1 wjrSXmyU1rcr6v7lhJfQxNOd5OIpY4LvvtvkCoRHtpEYgFtNVtvd4xTrGtK6Z007mIeL GctTbv/UpiUQaijwzYExn+fS2KoxEnhI81yfDTHJmQBIwa5MrHNCoVJw3SPdx0N/bKaW FG3AAG6dmcBADvkUJQ9woq+7wqjKWRi0FQlyVvpqVaANlLt2/jTTiJiKYZO1ETWrLGCH CslQ== 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-id:mime-version:subject :cc:to:references:in-reply-to:from:organization:dkim-signature; bh=i+a8DGHRj3jW50Valrkn+7VRWxzc0jyAL0po+eTjD1I=; b=Flrrz3K2lqK4xTpqyLefp/3xjnpJbhBmE+Mqhb1aBFomQONceD9haSXIK9C9zdKxd/ GjRY0Dwvg1S8ONrvV5jX3UdY1l4+Ki2HTmvWZszGYH8g6laiK9tNiL1oy1J5biiw+xQr k4B5BIPnLGAB5j93cceYCSb0oYvPvAGSrRQ6O40pnnwKwEGw+dXDGL5PU4Zh55CumZNO TfKIDAOP+F9j+o6ra7lKTqQpF20J0kadSfDaQlUh3NHuNf7S5K5PO/+EL+pIt7HRfEAz 4fqLBd4TQBpWuETZuOj89zub3qw1HsDM31Vor+rdcQukLz1nYudN6BDWHimMLEdTrbDr b3oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BxDjNUx5; 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 t22-20020a17090a1c9600b0025677f1197asi7715294pjt.12.2023.06.19.09.56.36; Mon, 19 Jun 2023 09:56:50 -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=BxDjNUx5; 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 S229895AbjFSQs0 (ORCPT + 99 others); Mon, 19 Jun 2023 12:48:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbjFSQsZ (ORCPT ); Mon, 19 Jun 2023 12:48:25 -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 608DFFE for ; Mon, 19 Jun 2023 09:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687193256; 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: in-reply-to:in-reply-to:references:references; bh=i+a8DGHRj3jW50Valrkn+7VRWxzc0jyAL0po+eTjD1I=; b=BxDjNUx51vK8CEsffq6+XEZuXA1E9eqWgnVX4x+/Whyi7z94vyZdHLvRinv1R+x8WWwTa9 9tayqfDSoO45F3P3ApVFUFbUwo2Qc0f9vd2EOq+cfHSK3oxRvSqdcaCNGmGkH7Db0ljtEu qSjhLINTPDlmv5HmpBWY4XYD21POui0= 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-302-ojfv7mcJNBW2RxY_gMc9Ug-1; Mon, 19 Jun 2023 12:47:30 -0400 X-MC-Unique: ojfv7mcJNBW2RxY_gMc9Ug-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4C1B858287; Mon, 19 Jun 2023 16:47:29 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B601112132D; Mon, 19 Jun 2023 16:47:27 +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 In-Reply-To: References: <1679829.1686785273@warthog.procyon.org.uk> <426353.1686911878@warthog.procyon.org.uk> To: Herbert Xu Cc: dhowells@redhat.com, netdev@vger.kernel.org, syzbot+13a08c0bf4d212766c3c@syzkaller.appspotmail.com, syzbot+14234ccf6d0ef629ec1a@syzkaller.appspotmail.com, syzbot+4e2e47f32607d0f72d43@syzkaller.appspotmail.com, syzbot+472626bb5e7c59fb768f@syzkaller.appspotmail.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jens Axboe , Matthew Wilcox , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] crypto: af_alg/hash: Fix recvmsg() after sendmsg(MSG_MORE) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1132300.1687193246.1@warthog.procyon.org.uk> Date: Mon, 19 Jun 2023 17:47:26 +0100 Message-ID: <1132301.1687193246@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Herbert Xu wrote: > Anyway, why did you remove the condition on hash_free_result? > We free the result if it's not needed, not to clear the previous > hash. So by doing it uncondtionally you will simply end up > freeing and reallocating the result for no good reason. The free here: if (!continuing) { if ((msg->msg_flags & MSG_MORE)) hash_free_result(sk, ctx); only happens in the following case: send(hashfd, "", 0, 0); send(hashfd, "", 0, MSG_MORE); <--- by this and the patch changes how this case works if no data is given. In Linus's tree, it will create a result, init the crypto and finalise it in hash_sendmsg(); with this patch that case is then handled by hash_recvmsg(). If you consider the following sequence: send(hashfd, "", 0, 0); send(hashfd, "", 0, 0); send(hashfd, "", 0, 0); send(hashfd, "", 0, 0); Upstream, the first one will create a result and then each of them will init and finalise a hash, whereas with my patch, the first one will release any outstanding result and then none of them will do any crypto ops. However, as, with my patch hash_sendmsg() no longer calculated a result, it has to clear the result pointer because the logic inside hash_recvmsg() relies on the result pointer to indicate that there is a result. Instead, hash_recvmsg() concocts the result - something it has to be able to do anyway in case someone calls recvmsg() without first supplying data. David