Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4916021imm; Fri, 18 May 2018 12:56:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrFqTnJABsHC2e8bFkzYf4YOASVwEpJflBpMQEqaMmASzcEXd2K644DWQziV3x4LMBuRFtV X-Received: by 2002:a62:a50c:: with SMTP id v12-v6mr10722862pfm.237.1526673394388; Fri, 18 May 2018 12:56:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526673394; cv=none; d=google.com; s=arc-20160816; b=jX/jHooGZHr6QRa2BivSvy+NeecbnR7XOCCKvvThPXLF8OEcrtVxAH2a1S5JEBh5N7 SghmvogkAqZiez76drK+L+q6VBQU4Kdp9Mqh8dQA31IBEfwATFjbc6HI2UWHGY6sTnLT a1LyRCJbwvn0lXOXo09CtMXwKaEXBR2+TEOLY5jHlhfl0M8rt3gxGMSfMtfkFXBm+nUP TzXzXsT0HoatVb1lvG76er773wwd5/b6df/s0YDJLjYyJEdZoLK0Ft/3CaTlAjyCZJW3 8M0dItvCqFz/YdigDCQt26uu/LBjY5GzRrRHFZL/DZF5NiO3TJwaOKH/YOHYaVxPgrQJ 7D4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=uAQyW5tmNLUoNV03xpqELANwWikn1RrEiPIvpHhGdHw=; b=aF2Tz8dLtjdt56xaqPtcyCPJ9ab5XCIJGB/T+iIxKBKVaLzXR/rq841on8X90HSIyu 09MsGCv+PaUsCjKjwNIryu/GY4kATJs+xJHY/k1+PHs4dgcUOVT95ZabASGow3MPpCWt HakUnlm1h2W6LYPjldpnQoja29Cby95AdQ0uRAxqpdNItLKct7t08iFT8hYpvFs4B+FZ DSTPSore99u7Pequas1XRikUUF+u5JTiHbC3PGnBdGnR85tWeE2L1B9/yIaCRMkMnMhG lyOKiqRJa5BaU5tqY/c7+7Y/wrA57tt+eI77YEryp8w90kyzJW8g4LCQ48VIIJacdpOo qGJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=c/++3ktf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3-v6si2043919pgc.300.2018.05.18.12.56.20; Fri, 18 May 2018 12:56:34 -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; dkim=pass header.i=@umn.edu header.s=google header.b=c/++3ktf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752022AbeERTz5 (ORCPT + 99 others); Fri, 18 May 2018 15:55:57 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:32794 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751197AbeERTzx (ORCPT ); Fri, 18 May 2018 15:55:53 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id ADB9CCC1 for ; Fri, 18 May 2018 19:55:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dtBFPI2wCzRP for ; Fri, 18 May 2018 14:55:52 -0500 (CDT) Received: from mail-it0-f71.google.com (mail-it0-f71.google.com [209.85.214.71]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id 81E76C75 for ; Fri, 18 May 2018 14:55:52 -0500 (CDT) Received: by mail-it0-f71.google.com with SMTP id i130-v6so2534870iti.0 for ; Fri, 18 May 2018 12:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=uAQyW5tmNLUoNV03xpqELANwWikn1RrEiPIvpHhGdHw=; b=c/++3ktf2L1NmVchypGHXZVCO2x8bXpT4/48Ri9skLpd03IDIU5fdwKsYV8dxfnpJa igHUtE+ieY9H9SVAcpr3rkxmQvdWV0pS8h5L5P3V5g5ll8u+JSreqBbbYQzsTmFA5ZGt MLaF4IVmP7Lkw2KF8ebOjLspKHeAn1L65MajrKTQdnc7cMAbomb9+pr39cNEyn9n4qnf PGhJ9JgaxHDCDU//aOdSbhCrtToHiPOFqZo03RvPFPtBaOtVa/dnHZXsmhr2G2MwLQD7 5ZfnvhW0Qh4IiCU60MH6wIFzHBXPgnnmFg+hH6+sV66p+vZPaUrhcs9c8lPUs/ePJ5Co zYGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uAQyW5tmNLUoNV03xpqELANwWikn1RrEiPIvpHhGdHw=; b=ZQyueazEn4lNynGLE50L1qW1AqMwLbJr15GyArg7Mvs0CJbb0bMWQLb7WaVKGnzHyd 0qxW7zaMdp863k8X3odw0Q0DiNfPCUBN8LFtZ2hDJfihNO2iph22dHkNj29t5iyIronv k/bfycvai1oXCIxgifPiogFO+0XQVx4iuGYZli01ib16P4xCtsRE/ETtmnYpeXE8K3QR BYSiM9A5dkqQzhmry2KNhmcvSQ03GReSgJa2ND5Xao7kqijn8oTGflJVythzWGbrfA4W 9MIA1kQ6xNJqezBWeQiZ6SmQA9o3EOx3z0YxKDGMr6JVFJ6D4J4U+l9nmXYmI2soc8vO d6qQ== X-Gm-Message-State: ALKqPwcRVX8zP1e51JB5JzjS3fjjLwEL7NZeRLAuLkL3yqGT4CngJrC7 evQV5oPA19OoI7Y518dcB2QbrcU6F2GbXtChIeNrZtMW+yqeQJX8C/fVOleM8LG88r0TY+Snfch 1RB8DgKtEhKgKK/6O45B9BXaMhFlf X-Received: by 2002:a6b:c38b:: with SMTP id t133-v6mr11731510iof.197.1526673352196; Fri, 18 May 2018 12:55:52 -0700 (PDT) X-Received: by 2002:a6b:c38b:: with SMTP id t133-v6mr11731500iof.197.1526673351995; Fri, 18 May 2018 12:55:51 -0700 (PDT) Received: from cs-u-cslp16.cs.umn.edu (cs-u-cslp16.cs.umn.edu. [134.84.121.95]) by smtp.gmail.com with ESMTPSA id i133-v6sm4662008itf.15.2018.05.18.12.55.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 May 2018 12:55:51 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Kangjie Lu , Harsh Jain , Herbert Xu , "David S. Miller" , Atul Gupta , Michael Werner , Casey Leedom , linux-crypto@vger.kernel.org (open list:CXGB4 CRYPTO DRIVER (chcr)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] crypto: chtls - fix a missing-check bug Date: Fri, 18 May 2018 14:55:35 -0500 Message-Id: <1526673338-486-1-git-send-email-wang6495@umn.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In do_chtls_setsockopt(), the tls crypto info is first copied from the poiner 'optval' in userspace and saved to 'tmp_crypto_info'. Then the 'version' of the crypto info is checked. If the version is not as expected, i.e., TLS_1_2_VERSION, error code -ENOTSUPP is returned to indicate that the provided crypto info is not supported yet. Then, the 'cipher_type' field of the 'tmp_crypto_info' is also checked to see if it is TLS_CIPHER_AES_GCM_128. If it is, the whole struct of tls12_crypto_info_aes_gcm_128 is copied from the pointer 'optval' and then the function chtls_setkey() is invoked to set the key. Given that the 'optval' pointer resides in userspace, a malicious userspace process can race to change the data pointed by 'optval' between the two copies. For example, a user can provide a crypto info with TLS_1_2_VERSION and TLS_CIPHER_AES_GCM_128. After the first copy, the user can modify the 'version' and the 'cipher_type' fields to any versions and/or cipher types that are not allowed. This way, the user can bypass the checks, inject bad data to the kernel, cause chtls_setkey() to set a wrong key or other issues. This patch reuses the data copied in the first try so as to ensure these checks will not be bypassed. Signed-off-by: Wenwen Wang --- drivers/crypto/chelsio/chtls/chtls_main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/chelsio/chtls/chtls_main.c b/drivers/crypto/chelsio/chtls/chtls_main.c index 007c45c..39aab05 100644 --- a/drivers/crypto/chelsio/chtls/chtls_main.c +++ b/drivers/crypto/chelsio/chtls/chtls_main.c @@ -491,9 +491,13 @@ static int do_chtls_setsockopt(struct sock *sk, int optname, switch (tmp_crypto_info.cipher_type) { case TLS_CIPHER_AES_GCM_128: { - rc = copy_from_user(crypto_info, optval, - sizeof(struct - tls12_crypto_info_aes_gcm_128)); + /* Obtain version and type from previous copy */ + crypto_info[0] = tmp_crypto_info; + /* Now copy the following data */ + rc = copy_from_user((char *)crypto_info + sizeof(*crypto_info), + optval + sizeof(*crypto_info), + sizeof(struct tls12_crypto_info_aes_gcm_128) + - sizeof(*crypto_info)); if (rc) { rc = -EFAULT; -- 2.7.4