Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7269974rwd; Mon, 19 Jun 2023 21:51:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6tELA0nzAVQVLVDBdx24VyhSIsqkQc2RhFdW4TyoBEtBBUUrZdO+XHZvfax5dgO2xyePo/ X-Received: by 2002:a17:902:ecc6:b0:1b1:9272:55e2 with SMTP id a6-20020a170902ecc600b001b1927255e2mr14403906plh.3.1687236709010; Mon, 19 Jun 2023 21:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687236708; cv=none; d=google.com; s=arc-20160816; b=izdgGcHjYNonmzfgCQVAwKVRrQFvXvdJ1j2t3h4URE44zGNhED2I+Etgk9ReNWB8oI DnmOxiIk1/XRczqMCuiHlS71H9ec0UUT+yWCZmZxJeCDr86fvDghW+JO9S6wiO4Qw4U9 ESnXRN4BxsoXZWXAzZ7AAJzEEWY8wUdKitHcKfv6UMyujo4yjfq+pWEucL35eCXDBIfu 8eHfR406uPFvdL72k2MSyL1HcaTX1GKnQ2KYcewkuYcfF5xmPxrOP8oYolgUf841pjh9 U1p8vWbXiVnbN+1IFawzt6A8kqXAvpgNE8/f9GTShFnhuynzV900E9VqfqJ+YOpMUG7i 7qsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=9xzaC7/2Dm+t8ZRw/rKpPlCiaqKS8jpr2miHVj2Au0s=; b=cb7E5Q15pb9ap9FExXuUMfmSbnR0QHLodSBYw2Z1H2+FVMQS9sxiEZXABaE9whczNn 2/m+ukwCtEfHFipBHwtImYbrtX3/F1cNb3e6UbMqe3ZgOJJz+opTNVll1nsZbZ4ihgip an0+ETKqSRH7pDLOz187BNLHHkgLImAgyQ0lJJcf3YW/vJ96SDWYuQcM5uir7b6sLaWK PH7kqgLGuTr1t8dFUxvTmF/cum+80I2wqrNj2ZIavcYS2gVAPhiP4qKRF9xX4VCADWPn /vB28mwTX2awSPIMwXzMZWU8eZQuvv9lpGt/JLQhraU/43w0coM15oLaDj8kvL65/IDY lklg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a170902e19500b001a67a19331dsi1035797pla.202.2023.06.19.21.51.30; Mon, 19 Jun 2023 21:51:48 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230020AbjFTEs3 (ORCPT + 99 others); Tue, 20 Jun 2023 00:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbjFTEsM (ORCPT ); Tue, 20 Jun 2023 00:48:12 -0400 Received: from 167-179-156-38.a7b39c.syd.nbn.aussiebb.net (167-179-156-38.a7b39c.syd.nbn.aussiebb.net [167.179.156.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2D8210E4; Mon, 19 Jun 2023 21:48:09 -0700 (PDT) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1qBTHE-004xjz-Qx; Tue, 20 Jun 2023 12:47:37 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Tue, 20 Jun 2023 12:47:36 +0800 Date: Tue, 20 Jun 2023 12:47:36 +0800 From: Herbert Xu To: David Howells Cc: 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) Message-ID: References: <1679829.1686785273@warthog.procyon.org.uk> <426353.1686911878@warthog.procyon.org.uk> <1132301.1687193246@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1132301.1687193246@warthog.procyon.org.uk> X-Spam-Status: No, score=2.7 required=5.0 tests=BAYES_00,HELO_DYNAMIC_IPADDR2, PDS_RDNS_DYNAMIC_FP,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS,TVD_RCVD_IP, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** 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 On Mon, Jun 19, 2023 at 05:47:26PM +0100, David Howells wrote: > > 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 Yes and that's what I'm complaining about. > 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. This is correct. If MSG_MORE is not set, then the hash will be finalised. In which case if there is already a result allocated then we should reuse it and not free it. If MSG_MORE is set, then we can delay the allocation of the result, in which case it makes sense to free any previous results since the next request may not come for a very long time (or perhaps even never). Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt