From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39C40EB64D9 for ; Fri, 16 Jun 2023 01:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232658AbjFPBES (ORCPT ); Thu, 15 Jun 2023 21:04:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbjFPBEP (ORCPT ); Thu, 15 Jun 2023 21:04:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A09F297F for ; Thu, 15 Jun 2023 18:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686877414; 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: in-reply-to:in-reply-to:references:references; bh=kcEnbXGcWdas9JneXh0Lv5Rsvonbjggxw0qCFC163g8=; b=ELyNMjV05NMOei3qp9wQLjMosL7cNVerTg0JUaMN0pmf8oqH/sTP0uSAbE0X8itAhIP2fU sDVxyHH88831pDM5D2Q9hAXSXRgX093x/8BZCkW9mpvLV4NyObqrqsxFiw5jZn3a8ifzhh WosFGx1lM+Yt/RvhhKmHJgnIft4/mv8= 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-209-5ATaZ5wBOeK4-I-YWKB-ew-1; Thu, 15 Jun 2023 21:03:30 -0400 X-MC-Unique: 5ATaZ5wBOeK4-I-YWKB-ew-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D04D85A58A; Fri, 16 Jun 2023 01:03:30 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03B47492C38; Fri, 16 Jun 2023 01:03:28 +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: <000000000000b928f705fdeb873a@google.com> <1433015.1686741914@warthog.procyon.org.uk> To: Herbert Xu Cc: dhowells@redhat.com, syzbot , davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, syzkaller-bugs@googlegroups.com Subject: Re: [syzbot] [crypto?] general protection fault in shash_async_final MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <415468.1686877408.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Fri, 16 Jun 2023 02:03:28 +0100 Message-ID: <415469.1686877408@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Herbert, Here's a slightly more comprehensive test program for the hashing code to exercise some combinations of sendmsg, sendmsg+MSG_MORE and recvmsg. David --- #define _GNU_SOURCE #include #include #include #include #include #include #include #include #define OSERROR(R, S) do { if ((long)(R) =3D=3D -1L) { perror((S)); exit(1= ); } } while(0) static int hashfd; static unsigned char buf[1024], sbuf[1024]; static const unsigned char no_zeros[2] =3D { 0xe3, 0xb0 }; static const unsigned char one_zero[2] =3D { 0x6e, 0x34 }; static const unsigned char two_zeros[2] =3D { 0x96, 0xa2 }; static void do_send(unsigned int n, unsigned int flags) { struct msghdr msg; struct iovec iov[1]; int res; memset(&msg, 0, sizeof(msg)); iov[0].iov_base =3D sbuf; iov[0].iov_len =3D n; msg.msg_iov =3D iov; msg.msg_iovlen =3D 1; res =3D sendmsg(hashfd, &msg, flags); OSERROR(res, "sendmsg"); } static void do_recv(unsigned int ix, const unsigned char r[2]) { struct msghdr msg; struct iovec iov[1]; int res, i; memset(&msg, 0, sizeof(msg)); iov[0].iov_base =3D buf; iov[0].iov_len =3D sizeof(buf); msg.msg_iov =3D iov; msg.msg_iovlen =3D 1; res =3D recvmsg(hashfd, &msg, 0); OSERROR(res, "recvmsg"); printf("%3u: ", ix); for (i =3D 0; i < res; i++) printf("%02x", buf[i]); printf("\n"); if (buf[0] !=3D r[0] || buf[1] !=3D r[1]) fprintf(stderr, " ^ Bad result!\n"); } int main(void) { struct sockaddr_alg salg; int algfd, res; algfd =3D socket(AF_ALG, SOCK_SEQPACKET, 0); OSERROR(algfd, "socket"); memset(&salg, 0, sizeof(salg)); salg.salg_family =3D AF_ALG; strcpy(salg.salg_type, "hash"); strcpy(salg.salg_name, "sha256"); res =3D bind(algfd, (struct sockaddr *)&salg, sizeof(salg)); OSERROR(res, "bind/alg"); hashfd =3D accept4(algfd, NULL, 0, 0); OSERROR(hashfd, "accept/alg"); //res =3D setsockopt(3, SOL_ALG, ALG_SET_KEY, NULL, 0); //OSERROR(res, "setsockopt/ALG_SET_KEY"); = /* Test no send */ do_recv(__LINE__, no_zeros); /* Test single send of 0 */ do_send(0, 0); do_recv(__LINE__, no_zeros); do_send(0, MSG_MORE); do_recv(__LINE__, no_zeros); /* Test single send of 1 */ do_send(1, 0); do_recv(__LINE__, one_zero); do_send(1, MSG_MORE); do_recv(__LINE__, one_zero); /* Test single send of 2 */ do_send(2, 0); do_recv(__LINE__, two_zeros); do_send(2, MSG_MORE); do_recv(__LINE__, two_zeros); /* Test two sends of 1 */ do_send(1, 0); do_send(1, 0); do_recv(__LINE__, one_zero); do_send(1, 0); do_send(1, MSG_MORE); do_recv(__LINE__, one_zero); do_send(1, MSG_MORE); do_send(1, 0); do_recv(__LINE__, two_zeros); do_send(1, MSG_MORE); do_send(1, MSG_MORE); do_recv(__LINE__, two_zeros); /* Test send of 0 then send of 2 */ do_send(0, 0); do_send(2, 0); do_recv(__LINE__, two_zeros); do_send(0, 0); do_send(2, MSG_MORE); do_recv(__LINE__, two_zeros); do_send(0, MSG_MORE); do_send(2, 0); do_recv(__LINE__, two_zeros); do_send(0, MSG_MORE); do_send(2, MSG_MORE); do_recv(__LINE__, two_zeros); /* Test send of 2 then send of 0 */ do_send(2, 0); do_send(0, 0); do_recv(__LINE__, no_zeros); do_send(2, 0); do_send(0, MSG_MORE); do_recv(__LINE__, no_zeros); do_send(2, MSG_MORE); do_send(0, 0); do_recv(__LINE__, two_zeros); do_send(2, MSG_MORE); do_send(0, MSG_MORE); do_recv(__LINE__, two_zeros); return 0; }