Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10786691imu; Thu, 6 Dec 2018 06:49:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/WZUM65P/dFBrho8nbBFg81bOKPbRfpGW7LPAUcgfS8GoQVHTSowMAQPgehQ35ARjlGSHnb X-Received: by 2002:a65:534b:: with SMTP id w11mr24566250pgr.125.1544107753973; Thu, 06 Dec 2018 06:49:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544107753; cv=none; d=google.com; s=arc-20160816; b=D7JOIVaRmz6MdazkuithXDibfdio5evJT5NF0neYMJBjBbEM/tJHYg9nmYL15rXdQj NYl23XTb10xgOBGvlBmqi7bWBMz0zakj6K0iZBfy8x2S3O09OhLbXfRehiuyRQcOnBoQ HnhIhfTcQq42i80Hx1SoEA81jNS7y+8rK6EchpsX4zZ92ugjQWry5R3qQDHXBgGD+0s7 qHnlXq1sDQwhcjFySRYwoVUa1ZgGOpr36CNu7U0Rkp4soe7u4oss+t8OQ7/K0gaYp5bo bbH/Q+dAfAayzRxrplcFhriOjZ0t4nXvr/QEw6+Zf93oT06wvyEymoz9R7fFdmVk5k+Y AT0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6buT8TZLncU46Sj1pEXKjdxd2Vefk1Vr+SjpQBSVuds=; b=NLlHdEWM7ZJara6QyBrnpxyz87jFNmuyt0+/DbFLhTvxdhNpGNliozGAf3JfnEa/tA vTn8AlAJ5/pVRCUdsYgeT5+diinkSbJwxEiUoaxWmINa7HUAlrzR8jPgGX7oEF8flBaZ 79V50VhnT4PEKTm4rR80eUitcBu1VeN+pHp6fRaTpGaTKvTw/UUJYrK+0CesdK9UKJhF /GCz1blmDtqAc4ADZ3D9bZaKJQ8Nn8L28A4vi5R7nxOJ3NL2X5OTetzMYiiIvhsDReW6 1uoX7YqFaAWHYL59FidAT5BhHeG/07ENQeSJJXoyanjHQ7qQ5LlNJR3fs0LYOcpezpTY HrCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ClgG3pGZ; 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 n5si385351plp.294.2018.12.06.06.48.58; Thu, 06 Dec 2018 06:49:13 -0800 (PST) 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=@kernel.org header.s=default header.b=ClgG3pGZ; 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 S1731179AbeLFOp7 (ORCPT + 99 others); Thu, 6 Dec 2018 09:45:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:50670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730436AbeLFOp5 (ORCPT ); Thu, 6 Dec 2018 09:45:57 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BC37C2082B; Thu, 6 Dec 2018 14:45:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544107557; bh=6t903W8YieBXVB8S7S/OrC9gPH5xHWw4bwNCKdk3CRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ClgG3pGZ7beIiKxx24+Gf3KtbzMGYPh9aZHqwlqw2SVLbUXmp4skODO9oG88ruJQ9 YbzacJQ7LHG7zXIXMd3jo70f4Ys1u2/QG6sZscsXC0uLpjM6W/qu3SG4rj4z4hRTkG 6jxwE2NhdtfjPQ+Bf2UW1vpNV10TIsp+B4Pm/irM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Dryomov , Sage Weil , Ben Hutchings Subject: [PATCH 4.9 052/101] libceph: factor out __ceph_x_decrypt() Date: Thu, 6 Dec 2018 15:38:51 +0100 Message-Id: <20181206143014.552570407@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206143011.174892052@linuxfoundation.org> References: <20181206143011.174892052@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ilya Dryomov commit c571fe24d243bfe7017f0e67fe800b3cc2a1d1f7 upstream. Will be used for decrypting the server challenge which is only preceded by ceph_x_encrypt_header. Drop struct_v check to allow for extending ceph_x_encrypt_header in the future. Signed-off-by: Ilya Dryomov Reviewed-by: Sage Weil Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- net/ceph/auth_x.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) --- a/net/ceph/auth_x.c +++ b/net/ceph/auth_x.c @@ -69,25 +69,40 @@ static int ceph_x_encrypt(struct ceph_cr return sizeof(u32) + ciphertext_len; } +static int __ceph_x_decrypt(struct ceph_crypto_key *secret, void *p, + int ciphertext_len) +{ + struct ceph_x_encrypt_header *hdr = p; + int plaintext_len; + int ret; + + ret = ceph_crypt(secret, false, p, ciphertext_len, ciphertext_len, + &plaintext_len); + if (ret) + return ret; + + if (le64_to_cpu(hdr->magic) != CEPHX_ENC_MAGIC) { + pr_err("%s bad magic\n", __func__); + return -EINVAL; + } + + return plaintext_len - sizeof(*hdr); +} + static int ceph_x_decrypt(struct ceph_crypto_key *secret, void **p, void *end) { - struct ceph_x_encrypt_header *hdr = *p + sizeof(u32); - int ciphertext_len, plaintext_len; + int ciphertext_len; int ret; ceph_decode_32_safe(p, end, ciphertext_len, e_inval); ceph_decode_need(p, end, ciphertext_len, e_inval); - ret = ceph_crypt(secret, false, *p, end - *p, ciphertext_len, - &plaintext_len); - if (ret) + ret = __ceph_x_decrypt(secret, *p, ciphertext_len); + if (ret < 0) return ret; - if (hdr->struct_v != 1 || le64_to_cpu(hdr->magic) != CEPHX_ENC_MAGIC) - return -EPERM; - *p += ciphertext_len; - return plaintext_len - sizeof(struct ceph_x_encrypt_header); + return ret; e_inval: return -EINVAL;