From patchwork Thu Aug 27 07:14:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 264865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2C2AC433DF for ; Thu, 27 Aug 2020 07:15:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 756A620786 for ; Thu, 27 Aug 2020 07:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726826AbgH0HPF (ORCPT ); Thu, 27 Aug 2020 03:15:05 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:34218 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726123AbgH0HPF (ORCPT ); Thu, 27 Aug 2020 03:15:05 -0400 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.0.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1kBC7I-0004FM-7A; Thu, 27 Aug 2020 17:14:37 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Thu, 27 Aug 2020 17:14:36 +1000 Date: Thu, 27 Aug 2020 17:14:36 +1000 From: Herbert Xu To: Ard Biesheuvel Cc: Denis Kenzior , Andrew Zaborowski , Paul Menzel , Caleb Jorden , Sasha Levin , iwd@lists.01.org, "# 3.4.x" , Greg KH , LKML , "David S. Miller" , Linux Crypto Mailing List Subject: [v2 PATCH] crypto: af_alg - Work around empty control messages without MSG_MORE Message-ID: <20200827071436.GA30281@gondor.apana.org.au> References: <20200826120832.GA2996@gondor.apana.org.au> <20200826130010.GA3232@gondor.apana.org.au> <20200826141907.GA5111@gondor.apana.org.au> <4bb6d926-a249-8183-b3d9-05b8e1b7808a@gmail.com> <20200826221913.GA16175@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Thu, Aug 27, 2020 at 08:40:01AM +0200, Ard Biesheuvel wrote: > > It is part of iwd - just build that and run 'make check' > > With your patch applied, the occurrence of sendmsg() in > operate_cipher() triggers the warn_once(), but if I add MSG_MORE > there, the test hangs. I see. This is a different issue. The original kernel change was a bit too strict here and it is barfing at the fact that two successive sendmsg's of the same request both contain a control message. Here's an updated patch to allow this. ---8<--- The iwd daemon uses libell which sets up the skcipher operation with two separate control messages. As the first control message is sent without MSG_MORE, it is interpreted as an empty request. While libell should be fixed to use MSG_MORE where appropriate, this patch works around the bug in the kernel so that existing binaries continue to work. We will print a warning however. A separate issue is that the new kernel code no longer allows the control message to be sent twice within the same request. This restriction is obviously incompatible with what iwd was doing (first setting an IV and then sending the real control message). This patch changes the kernel so that this is explicitly allowed. Reported-by: Caleb Jorden Fixes: f3c802a1f300 ("crypto: algif_aead - Only wake up when...") Cc: Signed-off-by: Herbert Xu diff --git a/crypto/af_alg.c b/crypto/af_alg.c index a6f581ab200c..8be8bec07cdd 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -845,9 +846,15 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, } lock_sock(sk); - if (ctx->init && (init || !ctx->more)) { - err = -EINVAL; - goto unlock; + if (ctx->init && !ctx->more) { + if (ctx->used) { + err = -EINVAL; + goto unlock; + } + + pr_info_once( + "%s sent an empty control message without MSG_MORE.\n", + current->comm); } ctx->init = true;