Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2230947imm; Thu, 7 Jun 2018 07:25:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKITksaLwxv5I55zpU7x8nTjzSAK2wVsuQe6pDvB8FWlvDVM+h9g11ZKABuEGSXCW2ZELegN X-Received: by 2002:a17:902:7242:: with SMTP id c2-v6mr2191544pll.383.1528381533122; Thu, 07 Jun 2018 07:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528381533; cv=none; d=google.com; s=arc-20160816; b=fjGmpd4hVgdBNiszxkaIkSDoojF2Z+DGkb9ykqvgFyYp9I9J3UiD07KB+xEvS0iz/u cCWzQA7Uu2zlNouPQw6mzY7rUj3PqNH08wj+SlNntEWomlTCLy9Woufnjg3EcnKbxzjD QYvuT3wNzWBT56DCmx5squKzw7gZdIiq4X7vmOoHDVt+rYqI0ZVCpCV/ndKDkbgmViF9 HkoAwj1rQqZSBITFt9FAmlbrALBOzJsDT7B2C0arHazhaW4trx88CmRHcUkAtfA5HmXS 68kXxXgH976Crf1iKBkS7fqYpI1kji/yZZiACdkGEdZD9RLKO5KU3gMX3gBHiq4lmB+Y i82A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=HJkIA4y/38owxrJmyeFI7JmInqnZ6ZRJP3SWW3+P3CQ=; b=ruCnB0iSjTyobMJeL5HIPaj7Sifm9VfwByOf5dzjN0ln4DcXi21EL9Fxluq5iegB6i JIk7ggRFGt7VSfPLrTsJ9vtHYn9dSUaTQFf0Q+7MaDEceIumFol5LRHd1J+HAT9H1Ab+ T0XriZuFSU+0SeeXepoeMn7gIHPlF1pyroI0c+FcoHN0ryoBsyK+yvq78HLjjMsYv8Ur 6TburFJSPP+xiDT9KqlDw4fjhiXTVEf0/N6IOpNT91Q+XhqkDKV5AA1I8IkWMjIUXmvY lufmMOtGWND/RhV2+Lkz7XKWy2Pe02Fpz/nPRttD6SYTaAyTBcaEoIuMZ81Ze75HZPXm S8Fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j189-v6si9513172pfg.351.2018.06.07.07.25.18; Thu, 07 Jun 2018 07:25:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753747AbeFGOYA (ORCPT + 99 others); Thu, 7 Jun 2018 10:24:00 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40117 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933313AbeFGOX5 (ORCPT ); Thu, 7 Jun 2018 10:23:57 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbd-0005Zl-KU; Thu, 07 Jun 2018 15:09:37 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb7-00033r-Nu; Thu, 07 Jun 2018 15:09:05 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Anand Moon" , "Kamil Konieczny" , "Krzysztof Kozlowski" , "Herbert Xu" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 240/410] crypto: s5p-sss - Fix kernel Oops in AES-ECB mode In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Kamil Konieczny commit c927b080c67e3e97193c81fc1d27f4251bf4e036 upstream. In AES-ECB mode crypt is done with key only, so any use of IV can cause kernel Oops. Use IV only in AES-CBC and AES-CTR. Signed-off-by: Kamil Konieczny Reported-by: Anand Moon Reviewed-by: Krzysztof Kozlowski Tested-by: Anand Moon Signed-off-by: Herbert Xu [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/crypto/s5p-sss.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -426,15 +426,21 @@ static void s5p_aes_crypt_start(struct s uint32_t aes_control; int err; unsigned long flags; + u8 *iv; aes_control = SSS_AES_KEY_CHANGE_MODE; if (mode & FLAGS_AES_DECRYPT) aes_control |= SSS_AES_MODE_DECRYPT; - if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CBC) + if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CBC) { aes_control |= SSS_AES_CHAIN_MODE_CBC; - else if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CTR) + iv = req->info; + } else if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CTR) { aes_control |= SSS_AES_CHAIN_MODE_CTR; + iv = req->info; + } else { + iv = NULL; /* AES_ECB */ + } if (dev->ctx->keylen == AES_KEYSIZE_192) aes_control |= SSS_AES_KEY_SIZE_192; @@ -465,7 +471,7 @@ static void s5p_aes_crypt_start(struct s goto outdata_error; SSS_AES_WRITE(dev, AES_CONTROL, aes_control); - s5p_set_aes(dev, dev->ctx->aes_key, req->info, dev->ctx->keylen); + s5p_set_aes(dev, dev->ctx->aes_key, iv, dev->ctx->keylen); s5p_set_dma_indata(dev, req->src); s5p_set_dma_outdata(dev, req->dst);