From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 77D4B45BC0 for ; Thu, 24 Oct 2024 15:10:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6E10643469; Thu, 24 Oct 2024 15:10:19 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 65EA640281 for ; Thu, 24 Oct 2024 15:10:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729775417; 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=p0F0ReBcfdumzGJWIBpA9ncK6Ayi3pGzURVoo34rpQs=; b=b2x5GmgEl6zACQmWX9di8KPXvQ2dgwHJscQ2Su9bGjzMZ3I0XbD7+qx0qgQNPz/694UqTa 4BoXoeCeEpB/ehaamFsIfYHtbgWeMCGoDfKmrgNvtXe6bYGL+19PBEV/+n3sqsKgES/I7a +uHtc9xM1BRv5paBMQYZ8ZOM4heOLRA= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-cbEz_FIhOkG-wu4-faFq3w-1; Thu, 24 Oct 2024 09:10:15 -0400 X-MC-Unique: cbEz_FIhOkG-wu4-faFq3w-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-539e294566dso741080e87.3 for ; Thu, 24 Oct 2024 06:10:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729775414; x=1730380214; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p0F0ReBcfdumzGJWIBpA9ncK6Ayi3pGzURVoo34rpQs=; b=jGVrg4V1M/+nR1uv9o5xF9U57zACs/NjUS5GHCannNAPE9sLRJi7UNtDgQ3L9X4lMq TBeIauXKdqcgFnnjMJdoi4uLbD3yOKFOAJMrjxPYnz8YcpeaiWm6mjHDEr6Ansn15RWs csJqORTzcg/GtCzkvCN5PgZX/+ifLEKIRQLoklIVhcKZIeJUuVX9/lX5PU/O87ZcwQH0 +bWludp4gBHeHGWFttaZILerVl0QCjuJ//q8fTrYWar5/3Yzcro5xYUrtv2w2+i9ye1P uzqHQRxdD2z22ZbZb0J1dVLivWVQmKzZxJLGYndbjNRM2WiHr+bD0SWlJ3nvyHYa3BXZ hXkw== X-Forwarded-Encrypted: i=1; AJvYcCUKAbB2xXfqv+hlX/anSRO/aG6Mpr9yzk1k796x8qnNsxWEsbjV50/TfKNheenKypEiQz2P6Qo=@dpdk.org X-Gm-Message-State: AOJu0YyZEl7FMz8kMY32Jn5Exwaki7KcaPQ539jZHYgtIqIAkF+hSisv 5KvrcubzQP7N7uhNkV3VsF6Rj10l7geoqD+Wr7Jsk/NL6hIozZ8BWg/r7oBJtkQ6TUp1PrmaIaa rMV2pGgH6l/1bM07gsi81JC8/GFOiLYuAZKE5cke/UIhiyx5x/r8oKn2MiFbdIAg312Xr529Ora RejtgbsS0RPqlZocJw5TU= X-Received: by 2002:a05:6512:308b:b0:536:53a9:96d5 with SMTP id 2adb3069b0e04-53b1a3084c0mr3287603e87.17.1729775414106; Thu, 24 Oct 2024 06:10:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXMC673txeTDFeR0fkhUp1Da8lcBBsORSS09aDK9Efbhdbsy7tX8XYQvnUn/Dtwhm5R9tHDN3ihwApvxjTUBU= X-Received: by 2002:a05:6512:308b:b0:536:53a9:96d5 with SMTP id 2adb3069b0e04-53b1a3084c0mr3287576e87.17.1729775413731; Thu, 24 Oct 2024 06:10:13 -0700 (PDT) MIME-Version: 1.0 References: <20241024120535.2722316-1-david.marchand@redhat.com> <20241024120535.2722316-5-david.marchand@redhat.com> <98CBD80474FA8B44BF855DF32C47DC35E9F816@smartserver.smartshare.dk> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F816@smartserver.smartshare.dk> From: David Marchand Date: Thu, 24 Oct 2024 15:10:01 +0200 Message-ID: Subject: Re: [PATCH 4/6] crypto/openssl: fix 3DES-CTR with big endian CPUs To: =?UTF-8?Q?Morten_Br=C3=B8rup?= Cc: dev@dpdk.org, thomas@monjalon.net, ferruh.yigit@amd.com, stephen@networkplumber.org, mattias.ronnblom@ericsson.com, stable@dpdk.org, Kai Ji , Slawomir Mrozowicz , Tomasz Kulasek , Daniel Mrzyglod , Pablo de Lara , Michal Kobylinski X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On Thu, Oct 24, 2024 at 2:55=E2=80=AFPM Morten Br=C3=B8rup wrote: > > > From: David Marchand [mailto:david.marchand@redhat.com] > > Sent: Thursday, 24 October 2024 14.06 > > > > Caught by code review. > > > > Don't byte swap unconditionally (assuming that CPU is little endian is > > wrong). Instead, convert from big endian to cpu and vice versa. > > Yes looks like a bug. > I wonder if this PMD has more similar bugs... > grep bswap drivers/crypto/openssl/* says no. > > > @@ -110,9 +111,9 @@ ctr_inc(uint8_t *ctr) > > { > > uint64_t *ctr64 =3D (uint64_t *)ctr; > > > > - *ctr64 =3D __builtin_bswap64(*ctr64); > > + *ctr64 =3D rte_be_to_cpu_64(*ctr64); > > (*ctr64)++; > > - *ctr64 =3D __builtin_bswap64(*ctr64); > > + *ctr64 =3D rte_cpu_to_be_64(*ctr64); > > } > > But that's not all. > > There may be an alignment bug too; the way it is used in process_openssl_= cipher_des3ctr(), "ctr" is not guaranteed to be uint64_t aligned. > > How about this instead: > > ctr_inc(void *ctr) > { > uint64_t ctr64 =3D rte_be_to_cpu_64(*(unaligned_uint64_t *)ctr); > ctr64++; > *(unaligned_uint64_t *)ctr =3D rte_cpu_to_be_64(ctr64); > } > > Or this: > > ctr_inc(void *ctr) > { > uint64_t ctr64; > > memcpy(&ctr64, ctr, sizeof(uint64_t)); > ctr64 =3D rte_be_to_cpu_64(ctr64); > ctr64++; > ctr64 =3D rte_cpu_to_be_64(ctr64); > memcpy(ctr, &ctr64, sizeof(uint64_t)); > } > > Or use a union in process_openssl_cipher_des3ctr() to ensure it's uint64_= t aligned. Or declare ctr as a uint64_t in process_openssl_cipher_des3ctr directly, and remove this casting. --=20 David Marchand