From patchwork Fri May 21 15:19:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Aur=C3=A9lien_Aptel?= X-Patchwork-Id: 1482263 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=mimecast20200619 header.b=cnDGkLGv; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4FmqzJ2JSYz9sW1 for ; Sat, 22 May 2021 01:19:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237419AbhEUPVP (ORCPT ); Fri, 21 May 2021 11:21:15 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.111.102]:41830 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237383AbhEUPVO (ORCPT ); Fri, 21 May 2021 11:21:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1621610390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=saGODfxTGlwpESfyI+7NBm9F5gPWyeVCDnFemV8xYKk=; b=cnDGkLGvh5+hsvq7Qq4IeXjeZISSnhoEQWfcW/QuaeN0Q/LYdNiPXMDleMVRcw6S6rsJdu JNrqoqdyBDjKObwtB8+3xZmCVP+K3CFRm5KBwYSI73vsCWORxQ7qecelS46xnUZY/xB2Ak vRNfGJL6KAFwDXc0mg/CHtJpYiP+7NI= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2177.outbound.protection.outlook.com [104.47.17.177]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-28-KVz7p6eTN1e-PspBxIRJBQ-1; Fri, 21 May 2021 17:19:48 +0200 X-MC-Unique: KVz7p6eTN1e-PspBxIRJBQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lOjbjDAJyrbB3xhOMTF+NsIKyGfv4S8ZoxdpSKfcfjX1oyXVHNLpA8lGeN10A374kW/+gCZDIlDd4vWGYNIajDBDeTn2/FZNXICTaquBeXWC8eKszTjd/KapGPZOfDlif5vMcIHpLbF38LxvWKetDmBJ6HBsDK1Nty+N95gasM50f4jCloV90jLen0B4R82xDhHI3jyMZNDl4GAB+EJsflfTff19ZYaMixJEfAvZTqLbtYEinBeF2KPKppjDBDe/D9fX9UNIB5BHWZNQQ6st722qIyOtFpbikvb8WbXJ+Y//UCP5Iq8Sp47f3tAWAj0tSp1dmpvfVRj/4iMb4pDdoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3zNPPkVwmXZN+k7e/ui3bspD5sdQ2A/z8/Msr2NZE0k=; b=X0vomdeS2nBrsYD0IlhKVl+HBGaL3i7oXSpnG5dnLYuJPz0XcK4SkJfu5UbYaTvnyYSphvzHtXukEmiwk1mBLAiU/lgKGds0nX/FtJD7V8U9eTqrBVlDc7kw9kd6M7yNd7lAoO7MXmwahwRlJ3ZrEw8qAyXY40DQhBegw3498kTC7UnmTg8u9wQ9zFNlg3umLFXKmxrcrt90PumLok5oD1D3UGKVpgk7lrwt40/CpACpWNcre2NJXdkzat1P04/llaWFgxzLzCev+G1+SqNXZNk3+hPChAn+STVhXisFijdD0vy3j8b2IN3+hcbxt1J8cSd9Z3BF9dE2FAAcjR/MkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3359.eurprd04.prod.outlook.com (2603:10a6:803:3::28) by VE1PR04MB7453.eurprd04.prod.outlook.com (2603:10a6:800:1b0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.26; Fri, 21 May 2021 15:19:47 +0000 Received: from VI1PR0402MB3359.eurprd04.prod.outlook.com ([fe80::18e7:6a19:208d:179d]) by VI1PR0402MB3359.eurprd04.prod.outlook.com ([fe80::18e7:6a19:208d:179d%6]) with mapi id 15.20.4150.023; Fri, 21 May 2021 15:19:47 +0000 From: =?utf-8?q?Aur=C3=A9lien_Aptel?= To: linux-cifs@vger.kernel.org CC: smfrench@gmail.com, metze@samba.org, Aurelien Aptel Subject: [PATCH v1 1/2] cifs: set server->cipher_type to AES-128-CCM for SMB3.0 Date: Fri, 21 May 2021 17:19:27 +0200 Message-ID: <20210521151928.17730-2-aaptel@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210521151928.17730-1-aaptel@suse.com> References: <20210521151928.17730-1-aaptel@suse.com> X-Originating-IP: [2003:fa:713:d396:524:65d3:25:9e8c] X-ClientProxiedBy: ZR0P278CA0050.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::19) To VI1PR0402MB3359.eurprd04.prod.outlook.com (2603:10a6:803:3::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (2003:fa:713:d396:524:65d3:25:9e8c) by ZR0P278CA0050.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23 via Frontend Transport; Fri, 21 May 2021 15:19:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a5399381-9d1d-4edf-506d-08d91c6bdec8 X-MS-TrafficTypeDiagnostic: VE1PR04MB7453: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6Ulkij5Zp7C93hU6+0xWqi1xpeXnxjHCFXfmohP5P4Zcb5ppttHUvEogPCMOHukjSm/rSJ9KQY7j3263ar+ukBZVpg/0EYmEDow+MQxmyoGDae4vTjQccS3KB3yzuAFuMD6rmHXpPF4adUoEboMJk3/b/H+CWJlcNXILsSzg2hXEcd0y+ukD/gIpTuU45oiIQN2spF3iTdu1aQMcG8hUHRYtaP1OH9VuS1+GGMPxNLo/FHFPOyax11vTuhAZCz3S9nge2tCp6LAG1RsIWpdDum8D9Ji30nVxNiVWS7fus54It8yj0thUjvG2WpeHB1mDKobc6rhDRW4+icN2OHTqEMa6kYnd0NIrZDraMFY7cuncaUFrcJRvpCpRDS+zI6k8ynSqt3PxvRveBHq/eLbFC1IMdayYL8a5aeJVs9/i5+qbs2E+48GIBI25ZPVscRmFTWzQ2eEr8wdF/yTUpLNrSf2Vehd/13mbmjvy0+E5zM4v+5TuBu9eb48m4CmZJ0AX3gcGY/9AthYKZ16twXobYvHReibI63BQ+R6vsSAOlIzacgoaXfRyAdJ2SIxIdR5AF+CdUdeFMHv3A2SJOV846msPKYLduNnU18RqFAHd/ljx6krI2de39yrQnwKZTng+SZ2nTU+OleD5fh7f7efRTjpCXKa3lB8V13vFn3N3Uh5/NHSXnpdZ5Jox7FxZp1jorW+ELCAv7puZQj0ZI1/NEpuoJbQmbdKQPOqlJW2y5thApQu5zQAHcsbLH1C5E+MXWoCCzbAtC3/wT23De62M08dY1lgnzkinOiDfxiVGjh1ixf4OHm/AZv8qhr1RNStW1rjUmQtb1690ZVFiiGMU8bxr6W7tYWQAW6ZXBqCSZu4vqedylbcUf96YRRBeQeTN8WiY06XwMZmokSKcTx1pQj+csAtHuX7a7s2XBxM8wfplaXlIKk+Z44rb0nQ1Kr9zCgf4qWtL05X8xEZd4JMGKw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:5;SRV:;IPV:NLI;SFV:SPM;H:VI1PR0402MB3359.eurprd04.prod.outlook.com;PTR:;CAT:OSPM;SFS:(346002)(136003)(376002)(396003)(366004)(39860400002)(316002)(1076003)(66476007)(66556008)(8936002)(52116002)(6486002)(6496006)(186003)(8676002)(16526019)(2616005)(86362001)(66946007)(5660300002)(83380400001)(6916009)(6666004)(2906002)(478600001)(38100700002)(36756003)(107886003)(4326008)(23200700001);DIR:OUT;SFP:1501; X-MS-Exchange-AntiSpam-MessageData: Y168LK7nK1U7BXv/jgg8ZjfNBbiD65/RBihpDlg6Gid8Z0yRKqXdaHE8wrQKpxec4f1Y/yGhS16Jae6qyqLHDqTRPVJVgRcdK8JJtcXLIZ1ABfhuyolpl2sPVCXUtGP3Fe4OObRwT3cLbVEVz6SFt4ZmmNlXEeTikrTgqnPnaVWYTNlxmClywIAw30qjg7b1BLn5iP+OsD8G394+9ds+zl9bFvxW4FMzaCHzXvMri1r0oKij8E4/+5fWwYB1kzgfLD3qeju9Hpo4Vm544/Owj4jbH7iAoA6DrnHaITcu1mo6KPYC3AiQgapnlzapmYl535vpIcpkeIgd65IG34Cs43SCYdrpYRNOB5txR1guCyNO7k9aJgkedzvpOth5keTLusesoPO+NybsvsZ6Rpg3L3Q/hkTHrWcLudGUR1HHkSHQHcxH9IBe74y3lxxWOSeKnD6Et9DSyYp4nWy14Ug6jqxH4jyFco8DpYjxHp+mW4tV1a5VPfiaZlLK3oM2eB472halDIES3L2Xf2GIUe8l3ghlgNCAeaBEu+FPxmciUsfGeeqdocpLxNwxDpv3QI5Mk7/GKhpEP2Oafkdp+qmuyhdgzbO6vKaHEhr3o5pTypJCLc8jmt0gW5Xz5noVew1l1y4q/B/87jY8298iSFJwQJEJ1Meelj+lUXygqKhIYDNNOrvsIdtP8h/G83VmD7JeOmt3Hwi7coqndz5eOg9ZuhuveV8CKhdDKEIz0CAcyqEdWZDm3WA0mjD/+2C/0HWzcPgZP4nsKwYncqxfKvqY4uuCiFu0U04T1BhZqO8HEPnw5B7DF7WdPuGlfoIS9IbS2Nb9vVI/vCtJl8E6sEBPWO3oCV25EnKrASgIka6JLnpnAvwYvOF0ywVB68YJj/vreJjpl1fiTobW2hMTzjsQCCgVMG4eklC0VkalFSYCoa9X3X+ytRdr0/L3kxbJ8bVOjQBh8FjSkYt6/HlW/KwAQIBVVyDiPRzZPwCqYfAAppLslzLMQeMipYXdLsROBY3u7PSJ/mKS54rpz0X1r0su564Fph+W5CdatnuajdKZuBUCrsh/Lp6nlv1MnJlQh8orymqcgigKndaJfLj3ixlSbVy4h+lCrtwRISuBmvvJ/NsecL0fY+GUiNUTZAmFO6/xd9OZH+pdZAWa87Av7t3vB1p4e1F3pyqRxp3l3BazJIGLrdfhlPNSKOeqJ3u4YOQF/m1Ly8iS1CFOF5aX9tD3faCMtQ3btnVOS5zAv/Jok116sMQ9eYgOcVV//oAuNUE6iBvv8uClzxz0I1EetBT8kOtt+oVsYy4c3zJ/EF+noDQPJz1Oh1rFug2Un/SZKMryhDtfFZJz48JmqlCIaR5kNTT+/M9h07JsdxaJ3CXE4bE= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a5399381-9d1d-4edf-506d-08d91c6bdec8 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3359.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2021 15:19:47.5413 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: P/LCsnWCbblmU2lvcFHlqkg/MhKSKBvt/eE4c7275bzpqKsKhJClIjLY+799BfJS X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7453 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Aurelien Aptel SMB3.0 doesn't have encryption negotiate context but simply uses the SMB2_GLOBAL_CAP_ENCRYPTION flag. When that flag is present in the neg response cifs.ko uses AES-128-CCM which is the only cipher available in this context. cipher_type was set to the server cipher only when parsing encryption negotiate context (SMB3.1.1). For SMB3.0 it was set to 0. This means cipher_type value can be 0 or 1 for AES-128-CCM. Fix this by checking for SMB3.0 and encryption capability and setting cipher_type appropriately. Signed-off-by: Aurelien Aptel --- fs/cifs/smb2pdu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 9f24eb88297a..c205f93e0a10 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -958,6 +958,13 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) /* Internal types */ server->capabilities |= SMB2_NT_FIND | SMB2_LARGE_FILES; + /* + * SMB3.0 supports only 1 cipher and doesn't have a encryption neg context + * Set the cipher type manually. + */ + if (server->dialect == SMB30_PROT_ID && (server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) + server->cipher_type = SMB2_ENCRYPTION_AES128_CCM; + security_blob = smb2_get_data_area_len(&blob_offset, &blob_length, (struct smb2_sync_hdr *)rsp); /* From patchwork Fri May 21 15:19:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Aur=C3=A9lien_Aptel?= X-Patchwork-Id: 1482264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=mimecast20200619 header.b=FWvWu8AH; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4FmqzL4Fz6z9sW1 for ; Sat, 22 May 2021 01:19:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234899AbhEUPVU (ORCPT ); Fri, 21 May 2021 11:21:20 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:56913 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237421AbhEUPVR (ORCPT ); Fri, 21 May 2021 11:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1621610392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TCKopmHmH88ad9N1m8CpoCpgMCsFu3zI5iDygLRo8cE=; b=FWvWu8AH4dxFXKJXl4RhU7BaD74cn1EXVaFH5pmuChZAvreuwHI1vD1B6DN36OHbuWORHQ rcwO57gezT30y/2yMt++KvJJl8MEHYnr6Hmwfz1Yg7qOlTHO/S1+tNkHKfpbYN5tOdPV/Q eGwGcQGKEpz+zZ0Xez9FqlAjfA4FJ4E= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2171.outbound.protection.outlook.com [104.47.17.171]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-17-9VnvBE1cM7qaXTVHV8_KtQ-1; Fri, 21 May 2021 17:19:51 +0200 X-MC-Unique: 9VnvBE1cM7qaXTVHV8_KtQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XWBkFAW6Tb2GGvWuBdhBltg8FVuC8VXQr4LNtGg1Wbo6+iDpAWBc4DjPgVZC8WDiTKYtOSKW+Mcuxh2xYmeqPw8NodOpNbpYPh0zhI6O7fEFM/T+XFWe01enwifo6+1nwdleTfIB3Jx1otNDHFBYY/aon6PiV3Hx8BzFk4Jk4hSPPLATpjSDYoqE0/N5UKbn7AqQOvwJHKX6o/iOh6P/nzzVDWPydiq9VQjGXMJC9WgAeBQUa/6HF+ZtCyQdO+dyZRJG4vHWPYlMZ379NBMhapreCE+QbGLlIvzDrzy39PNVXy1PcG923cFifDSc6gkEirAGyuKVQB2W+wmw993vjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WhqPrVJFVe+uQrpkx+X226CIgsFgFBzhY1L/lobAge8=; b=XIIFuI8i97WNqA0ZALb2jQzVr5vt9GRAqHxkCEFbMHEgwVZtBjfN/PvksrW/92LO4vH0oC8oE1cZm3TVaKtakj7YQC0/LUxnKTIGA0OJ+64u/9ZlpAKXSV+DWnxW0y17YVYTYkZemk09RrcFG4+i5pALwPx64DXG2RHyflzknIWnloav/OD4cml0ohXJNVO5FBUvpV6X5FpM9YVQfWUjY3hyXxQPE8VhXq1enFsemOtuf9edQ8ro3H8DQT/FUFlYJmDzz7l2RKy3wWfLuPz290SFBia+o1cToICISct7qf8WpM1IjOpF+MRK7CzMkJf4lQA27aLmWRHmX1IHrrdnqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3359.eurprd04.prod.outlook.com (2603:10a6:803:3::28) by VE1PR04MB7453.eurprd04.prod.outlook.com (2603:10a6:800:1b0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.26; Fri, 21 May 2021 15:19:50 +0000 Received: from VI1PR0402MB3359.eurprd04.prod.outlook.com ([fe80::18e7:6a19:208d:179d]) by VI1PR0402MB3359.eurprd04.prod.outlook.com ([fe80::18e7:6a19:208d:179d%6]) with mapi id 15.20.4150.023; Fri, 21 May 2021 15:19:50 +0000 From: =?utf-8?q?Aur=C3=A9lien_Aptel?= To: linux-cifs@vger.kernel.org CC: smfrench@gmail.com, metze@samba.org, Aurelien Aptel Subject: [PATCH v1 2/2] cifs: change format of CIFS_FULL_KEY_DUMP ioctl Date: Fri, 21 May 2021 17:19:28 +0200 Message-ID: <20210521151928.17730-3-aaptel@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210521151928.17730-1-aaptel@suse.com> References: <20210521151928.17730-1-aaptel@suse.com> X-Originating-IP: [2003:fa:713:d396:524:65d3:25:9e8c] X-ClientProxiedBy: ZR0P278CA0052.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::21) To VI1PR0402MB3359.eurprd04.prod.outlook.com (2603:10a6:803:3::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (2003:fa:713:d396:524:65d3:25:9e8c) by ZR0P278CA0052.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23 via Frontend Transport; Fri, 21 May 2021 15:19:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d69945f2-49ff-41e5-be0f-08d91c6be065 X-MS-TrafficTypeDiagnostic: VE1PR04MB7453: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YO3z/EQhndc66dXMJ57Wn78w15xUARozWhEJXQ2IiLjr0JuKE9kJJjrWvJ5KSI8VdwVneVQLo53ItfPI/BiMTehrWfs2jFIhM6VIiSYbL29fi3m/FdO1junTMm1yh9mgPGj7fLq54HBjMuZsZYvDg1O1Myr34i6Jq2E6/1pDBKDlio0UGja8BxJTE8iWiIyTEdfyjPfxL3Zsjx2GRpInBdeUD8yoTKjK0Mfy5zlfkHAHYqApqVeOCIBsnYieabr0voe6Ue4/X+uJjvoUCaD1uADvnQ28Si6EuhhXwmBy8uYbzN4zHnC6um9uqPhqjU8Sdlv7DvUFOIgBdnm4NbGk6TJadRTtdbhnT/4l38EHVnbKHELMlJ5RhOaU86wGSke8Bfev48GHrW9jpwQ1Qq7J0LB0o1NSJpz3nwkCcYdIY8DDoAJMcdszBVTjivLUjK3IhB/i8KQVoNcOId6NXopMZKTpvjPYoaT0ZFThWmecO0/Go+ZuXxaJ2+Mw30gr/D+pF3tSd6osm+01fh7Xnzowh5xH3KVBilHcuq++FbjaJNOPfvw+Ruwp+5/SQnthRqHvdYkF3U67AtCjcUWF+owq20wBeyt7ROWO7HZKLytMKjOe5YNwwSbf30TdQ1SrOaPt3OEqinQ16L8qD/ziGMfpFnViRFiBzfQDsUiVjr0qy8qe6rPcRM4oYajGeZtd5bnsAMPfz6XQ03M5kwe03a0FXtBsnmGwe5fumJ7VRyIb7oB8zufvfdLtqBSxj3bVeezOeCB99EAe9xM2mkY8PiPRbLWJCCIfCLz18L/FZuAXdAcVVyimDJoctv+eQoE2qAO5Nu9GywML+8sSqLBZMBzbGP8KPCMPxPrm0wNleUBkTqT84iW5jceWoW6rZpruBx3J5W8S4Uo85X9fWMKE5+v8pk4MYD5l70Uaw+8uKXMx66Ll34tQeQPPJiqOjdB+64pzLKqJTVqnhW9WaXaWpbPjlw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:5;SRV:;IPV:NLI;SFV:SPM;H:VI1PR0402MB3359.eurprd04.prod.outlook.com;PTR:;CAT:OSPM;SFS:(346002)(136003)(376002)(396003)(366004)(39860400002)(316002)(1076003)(66476007)(66556008)(8936002)(52116002)(6486002)(6496006)(186003)(30864003)(8676002)(16526019)(2616005)(86362001)(66946007)(5660300002)(83380400001)(6916009)(6666004)(2906002)(478600001)(38100700002)(36756003)(107886003)(4326008)(23200700001);DIR:OUT;SFP:1501; X-MS-Exchange-AntiSpam-MessageData: 5xfTUwuIR15yibyMdMJ1XXf5ZutUq6oW7kNGhX0VDKzqQsNMv/iJzWtbKhwzZVrGPRRz/zSBjG+hKCALMc551PrD1SKCgS7ss0qwrAPz3OpXOvC7GLIA7yJgY3vPk82Qymj30XwaKJD2YWjLoEcAJ8FtIjQrgVKwpxTiT+iz/wFDXkYSoaflChmVNttbu0NGMWJNrQhrGxY3tomsFOG+luqBAvXtxFpMDTdAxlANiLjKqMhd9KcvgIeikzjQEduCnto+6aOQJxx3tuHbreCwxUP6y2i/xcAuDL/EN0ohRqbO0kBiAAX0Hvz/AXy+Cb2xpZOjTM7oj1JyhOR6IsBMoSp+13s/wH00p7k3X9DjX2V3rDGADh2vP0lN3GNZhqEPmiNe0Zf+KRevB1idobZXvNhUKdtg/nd06kwMLQxYtfQyj5h/FoLwZyV3Hjt8+mdXOwpTPWEm1MheapeqKf4665uMt+p35Sm1ltWEzf7vSlISMFzcWBCOZFgYcCPhO8dZRz42HCNrXYkLkANWa/j3CSZxiZinR1Q7TKEB05hVTWKzRhC48IqSewAcSxJJqG2v1iY1jinjOo3RiCwOKAqefqfvttQcJAEPsXf/1OUaNnqtoTv1Gw0ppR8aWn80fVNxjWGq8mm0Pr1gLXvX5VzkgaCD3gdrfonHHGxRdzDzU502BgUfgMn6XnXL8H17Hlq85rvZaIQhQTKRCj3bw/Zlwy3Pt3ugyCu94V1i5RVjehs3D2GdcfMBbqQSDXQdKmiyKin8x8UIESKA/2QSLA7hHXmVIYENSnTf8lpQedFRKr1P4Ub4Qxe8Ev3bBygEgfikXjPoU6FP2bUyntTSVWwpzLjWM1Zzfuf+RY02bCaO5ZgJe3aFxo42NO3kujeE2ZNDNxWwHmM5t8rymjy9n/TDDRN0n2JtASuWVEb6pIM8FCXbFx3Le+FolTsznzPtjgwK7mrSW9hTlE09zc195f40zplUR7UTaCRFHBRKRN5GehBKp6kqF6rhVzADCA2uNvCImBLBfyKt+53vycXMNdUdtCb8CEjE7TPw0+F5D2sUx1vXvFWHA0b0djDlimt8zx1VMgTgn8eoCNBJUgSjseqYI4f0HU9HwoEvyroB/N/yitKCs2WEogGHPlJAQOCOedWdQZM5rdMUvSGr8PGWMYwAGOix9kb1s3HfmGJuX5an3EDYA+gSlin4e9uYPA54jvIW+9GuEp/F3l70gw2R+SrYOBnkvQk0iFRzd0fWRn40Wx18+y5rkbhZUWY25+y9BG/IA+I9uPPVcMTrcqmKaQCzjZbogSy3zGO5TPHlnvqkAXGbqo6WPLtoosSESzy6q/a7RgI+e+5dlFBf1VtoasqEyB4b1P0+g7P/Yyo+aoOkWZA= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d69945f2-49ff-41e5-be0f-08d91c6be065 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3359.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2021 15:19:50.2667 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2UZeGw9P3mRFOKP/z0BGvIKoqRyCzOhLYU8blSprr1OUqO5+DdznM8ZQWd+Y1RvS X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7453 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Aurelien Aptel Make CIFS_FULL_KEY_DUMP ioctl able to return variable-length keys. * userspace needs to pass the struct size along with optional session_id and some space at the end to store keys * if there is enough space kernel returns keys in the extra space and sets the length of each key via xyz_key_length fields This also fixes the build error for get_user() on ARM. Sample program: #include #include #include #include #include struct smb3_full_key_debug_info { uint32_t in_size; uint64_t session_id; uint16_t cipher_type; uint8_t session_key_length; uint8_t server_in_key_length; uint8_t server_out_key_length; uint8_t data[]; /* * return this struct with the keys appended at the end: * uint8_t session_key[session_key_length]; * uint8_t server_in_key[server_in_key_length]; * uint8_t server_out_key[server_out_key_length]; */ } __attribute__((packed)); #define CIFS_IOCTL_MAGIC 0xCF #define CIFS_DUMP_FULL_KEY _IOWR(CIFS_IOCTL_MAGIC, 10, struct smb3_full_key_debug_info) void dump(const void *p, size_t len) { const char *hex = "0123456789ABCDEF"; const uint8_t *b = p; for (int i = 0; i < len; i++) printf("%c%c ", hex[(b[i]>>4)&0xf], hex[b[i]&0xf]); putchar('\n'); } int main(int argc, char **argv) { struct smb3_full_key_debug_info *keys; uint8_t buf[sizeof(*keys)+1024] = {0}; size_t off = 0; int fd, rc; keys = (struct smb3_full_key_debug_info *)&buf; keys->in_size = sizeof(buf); fd = open(argv[1], O_RDONLY); if (fd < 0) perror("open"), exit(1); rc = ioctl(fd, CIFS_DUMP_FULL_KEY, keys); if (rc < 0) perror("ioctl"), exit(1); printf("SessionId "); dump(&keys->session_id, 8); printf("Cipher %04x\n", keys->cipher_type); printf("SessionKey "); dump(keys->data+off, keys->session_key_length); off += keys->session_key_length; printf("ServerIn Key "); dump(keys->data+off, keys->server_in_key_length); off += keys->server_in_key_length; printf("ServerOut Key "); dump(keys->data+off, keys->server_out_key_length); return 0; } Usage: $ gcc -o dumpkeys dumpkeys.c Against Windows Server 2020 preview (with AES-256-GCM support): # mount.cifs //$ip/test /mnt -o "username=administrator,password=foo,vers=3.0,seal" # ./dumpkeys /mnt/somefile SessionId 0D 00 00 00 00 0C 00 00 Cipher 0002 SessionKey AB CD CC 0D E4 15 05 0C 6F 3C 92 90 19 F3 0D 25 ServerIn Key 73 C6 6A C8 6B 08 CF A2 CB 8E A5 7D 10 D1 5B DC ServerOut Key 6D 7E 2B A1 71 9D D7 2B 94 7B BA C4 F0 A5 A4 F8 # umount /mnt With 256 bit keys: # echo 1 > /sys/module/cifs/parameters/require_gcm_256 # mount.cifs //$ip/test /mnt -o "username=administrator,password=foo,vers=3.11,seal" # ./dumpkeys /mnt/somefile SessionId 09 00 00 00 00 0C 00 00 Cipher 0004 SessionKey 93 F5 82 3B 2F B7 2A 50 0B B9 BA 26 FB 8C 8B 03 ServerIn Key 6C 6A 89 B2 CB 7B 78 E8 04 93 37 DA 22 53 47 DF B3 2C 5F 02 26 70 43 DB 8D 33 7B DC 66 D3 75 A9 ServerOut Key 04 11 AA D7 52 C7 A8 0F ED E3 93 3A 65 FE 03 AD 3F 63 03 01 2B C0 1B D7 D7 E5 52 19 7F CC 46 B4 Signed-off-by: Aurelien Aptel --- fs/cifs/cifs_ioctl.h | 25 ++++++-- fs/cifs/cifspdu.h | 3 +- fs/cifs/ioctl.c | 143 +++++++++++++++++++++++++++++++------------ 3 files changed, 126 insertions(+), 45 deletions(-) diff --git a/fs/cifs/cifs_ioctl.h b/fs/cifs/cifs_ioctl.h index 4a97fe12006b..4b3d33b2838d 100644 --- a/fs/cifs/cifs_ioctl.h +++ b/fs/cifs/cifs_ioctl.h @@ -72,15 +72,28 @@ struct smb3_key_debug_info { } __packed; /* - * Dump full key (32 byte encrypt/decrypt keys instead of 16 bytes) - * is needed if GCM256 (stronger encryption) negotiated + * Dump variable-sized keys */ struct smb3_full_key_debug_info { - __u64 Suid; + /* INPUT: size of userspace buffer */ + __u32 in_size; + + /* + * INPUT: 0 for current user, otherwise session to dump + * OUTPUT: session id that was dumped + */ + __u64 session_id; __u16 cipher_type; - __u8 auth_key[16]; /* SMB2_NTLMV2_SESSKEY_SIZE */ - __u8 smb3encryptionkey[32]; /* SMB3_ENC_DEC_KEY_SIZE */ - __u8 smb3decryptionkey[32]; /* SMB3_ENC_DEC_KEY_SIZE */ + __u8 session_key_length; + __u8 server_in_key_length; + __u8 server_out_key_length; + __u8 data[]; + /* + * return this struct with the keys appended at the end: + * __u8 session_key[session_key_length]; + * __u8 server_in_key[server_in_key_length]; + * __u8 server_out_key[server_out_key_length]; + */ } __packed; struct smb3_notify { diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h index b53a87db282f..554d64fe171e 100644 --- a/fs/cifs/cifspdu.h +++ b/fs/cifs/cifspdu.h @@ -148,7 +148,8 @@ #define SMB3_SIGN_KEY_SIZE (16) /* - * Size of the smb3 encryption/decryption keys + * Size of the smb3 encryption/decryption key storage. + * This size is big enough to store any cipher key types. */ #define SMB3_ENC_DEC_KEY_SIZE (32) diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c index 28ec8d7c521a..87b2f1309e6f 100644 --- a/fs/cifs/ioctl.c +++ b/fs/cifs/ioctl.c @@ -33,6 +33,7 @@ #include "cifsfs.h" #include "cifs_ioctl.h" #include "smb2proto.h" +#include "smb2glob.h" #include static long cifs_ioctl_query_info(unsigned int xid, struct file *filep, @@ -214,48 +215,112 @@ static int cifs_shutdown(struct super_block *sb, unsigned long arg) return 0; } -static int cifs_dump_full_key(struct cifs_tcon *tcon, unsigned long arg) +static int cifs_dump_full_key(struct cifs_tcon *tcon, struct smb3_full_key_debug_info __user* in) { - struct smb3_full_key_debug_info pfull_key_inf; - __u64 suid; - struct list_head *tmp; + struct smb3_full_key_debug_info out; struct cifs_ses *ses; + int rc = 0; bool found = false; + u8 __user *end; - if (!smb3_encryption_required(tcon)) - return -EOPNOTSUPP; + if (!smb3_encryption_required(tcon)) { + rc = -EOPNOTSUPP; + goto out; + } + + /* copy user input into our output buffer */ + if (copy_from_user(&out, in, sizeof(out))) { + rc = -EINVAL; + goto out; + } + + if (!out.session_id) { + /* if ses id is 0, use current user session */ + ses = tcon->ses; + } else { + /* otherwise if a session id is given, look for it in all our sessions */ + struct cifs_ses *ses_it = NULL; + struct TCP_Server_Info *server_it = NULL; - ses = tcon->ses; /* default to user id for current user */ - if (get_user(suid, (__u64 __user *)arg)) - suid = 0; - if (suid) { - /* search to see if there is a session with a matching SMB UID */ spin_lock(&cifs_tcp_ses_lock); - list_for_each(tmp, &tcon->ses->server->smb_ses_list) { - ses = list_entry(tmp, struct cifs_ses, smb_ses_list); - if (ses->Suid == suid) { - found = true; - break; + list_for_each_entry(server_it, &cifs_tcp_ses_list, tcp_ses_list) { + list_for_each_entry(ses_it, &server_it->smb_ses_list, smb_ses_list) { + if (ses_it->Suid == out.session_id) { + ses = ses_it; + /* + * since we are using the session outside the crit + * section, we need to make sure it won't be released + * so increment its refcount + */ + ses->ses_count++; + found = true; + goto search_end; + } } } +search_end: spin_unlock(&cifs_tcp_ses_lock); - if (found == false) - return -EINVAL; - } /* else uses default user's SMB UID (ie current user) */ - - pfull_key_inf.cipher_type = le16_to_cpu(ses->server->cipher_type); - pfull_key_inf.Suid = ses->Suid; - memcpy(pfull_key_inf.auth_key, ses->auth_key.response, - 16 /* SMB2_NTLMV2_SESSKEY_SIZE */); - memcpy(pfull_key_inf.smb3decryptionkey, ses->smb3decryptionkey, - 32 /* SMB3_ENC_DEC_KEY_SIZE */); - memcpy(pfull_key_inf.smb3encryptionkey, - ses->smb3encryptionkey, 32 /* SMB3_ENC_DEC_KEY_SIZE */); - if (copy_to_user((void __user *)arg, &pfull_key_inf, - sizeof(struct smb3_full_key_debug_info))) - return -EFAULT; + if (!found) { + rc = -ENOENT; + goto out; + } + } - return 0; + switch (ses->server->cipher_type) { + case SMB2_ENCRYPTION_AES128_CCM: + case SMB2_ENCRYPTION_AES128_GCM: + out.session_key_length = CIFS_SESS_KEY_SIZE; + out.server_in_key_length = out.server_out_key_length = SMB3_GCM128_CRYPTKEY_SIZE; + break; + case SMB2_ENCRYPTION_AES256_CCM: + case SMB2_ENCRYPTION_AES256_GCM: + out.session_key_length = CIFS_SESS_KEY_SIZE; + out.server_in_key_length = out.server_out_key_length = SMB3_GCM256_CRYPTKEY_SIZE; + break; + default: + rc = -EOPNOTSUPP; + goto out; + } + + /* check if user buffer is big enough to store all the keys */ + if (out.in_size < sizeof(out) + out.session_key_length + out.server_in_key_length + + out.server_out_key_length) { + rc = -ENOBUFS; + goto out; + } + + out.session_id = ses->Suid; + out.cipher_type = le16_to_cpu(ses->server->cipher_type); + + /* overwrite user input with our output */ + if (copy_to_user(in, &out, sizeof(out))) { + rc = -EINVAL; + goto out; + } + + /* append all the keys at the end of the user buffer */ + end = in->data; + if (copy_to_user(end, ses->auth_key.response, out.session_key_length)) { + rc = -EINVAL; + goto out; + } + end += out.session_key_length; + + if (copy_to_user(end, ses->smb3encryptionkey, out.server_in_key_length)) { + rc = -EINVAL; + goto out; + } + end += out.server_in_key_length; + + if (copy_to_user(end, ses->smb3decryptionkey, out.server_out_key_length)) { + rc = -EINVAL; + goto out; + } + +out: + if (found) + cifs_put_smb_ses(ses); + return rc; } long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) @@ -371,6 +436,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) rc = -EOPNOTSUPP; break; case CIFS_DUMP_KEY: + /* + * Dump encryption keys. This is an old ioctl that only + * handles AES-128-{CCM,GCM}. + */ if (pSMBFile == NULL) break; if (!capable(CAP_SYS_ADMIN)) { @@ -398,11 +467,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) else rc = 0; break; - /* - * Dump full key (32 bytes instead of 16 bytes) is - * needed if GCM256 (stronger encryption) negotiated - */ case CIFS_DUMP_FULL_KEY: + /* + * Dump encryption keys (handles any key sizes) + */ if (pSMBFile == NULL) break; if (!capable(CAP_SYS_ADMIN)) { @@ -410,8 +478,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) break; } tcon = tlink_tcon(pSMBFile->tlink); - rc = cifs_dump_full_key(tcon, arg); - + rc = cifs_dump_full_key(tcon, (void __user *)arg); break; case CIFS_IOC_NOTIFY: if (!S_ISDIR(inode->i_mode)) {