From patchwork Fri May 29 12:40:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 197695 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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_SANE_1 autolearn=ham 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 2D0EAC433E0 for ; Fri, 29 May 2020 12:41:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08FF220721 for ; Fri, 29 May 2020 12:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbgE2MlB (ORCPT ); Fri, 29 May 2020 08:41:01 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:40720 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbgE2MlB (ORCPT ); Fri, 29 May 2020 08:41:01 -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 1jeeJc-0005xg-GM; Fri, 29 May 2020 22:40:49 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Fri, 29 May 2020 22:40:48 +1000 Date: Fri, 29 May 2020 22:40:48 +1000 From: Herbert Xu To: Linux Crypto Mailing List , Stephan Mueller Subject: [PATCH] crypto: algif_skcipher - Do not perform zero-length ops Message-ID: <20200529124048.GA7283@gondor.apana.org.au> References: <20200529045443.GA475@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200529045443.GA475@gondor.apana.org.au> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org If a read(2) of less than a full block size is attempted we will end up doing a zero-length operation. This patch makes that return -EINVAL instead, which is what we did originally. Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory...") Signed-off-by: Herbert Xu diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index 4c3bdffe0c3a5..24dd2fc2431cc 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -85,6 +85,10 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg, if (ctx->more || len < ctx->used) len -= len % bs; + err = -EINVAL; + if (!len) + goto free; + /* * Create a per request TX SGL for this request which tracks the * SG entries from the global TX SGL.