Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4567177rwb; Tue, 20 Sep 2022 16:23:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6O9ZRwXRbKsFaFbt6/McIKkzlMpb0hMVzb8JHo1haMKh4xKv1ivuHeE6RGJOZ+j0AIpWtY X-Received: by 2002:a17:907:2e02:b0:77c:5020:b8ef with SMTP id ig2-20020a1709072e0200b0077c5020b8efmr18606013ejc.299.1663716181792; Tue, 20 Sep 2022 16:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663716181; cv=none; d=google.com; s=arc-20160816; b=P0lN4VB7wJKMsio8hLNqeV6otUKegsCv1m3OLoZkEpQTL2SDTWZh5kYnspOUhWtI0d Nr7TGEfJdxlptIcjitMtvgeQA3wrTUpRaDj9B8CAxfg+4ZchQy56LXXf+zlG2Uswgqdr Z5GXCcmm7UjPvgsX1Tf4aOTfqNBlqCZMvDyAkliYUxnNBwCB1TMKlcrCH4tBz+fmkCNT CcTgtDQ2NF1p4XXQ+u0a7upug2tpATQRv2whPF2udN/TPPsJ+V+SqncmWLqhdsT1teCB 5EXTrTZssnL2pvbel29In9AFFoiGIen0tcoZbaQZoPQ8U1yCSvH1cTO4TKJXRsvpUOEO 50eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=oYK6TumnSDP79KmzKKCHc3Thiq4B9cnHKK0N6TQXz+s=; b=fHDQDs8QWstuCF6B/4qSYFpgZTbbYYcYa6JVQb6esiJZGBzs8NEaUjz+dVa4lU/nM2 waUWOsQh/FKROviXVCFD4Fx4NbnTs9R9RVhpeGZ2z6pr+t/Q+fWwJhzpBAKXx9Ii0vHh x6k3q/dj6PwaVGRtJ1xxXfARhVPrtqnbW9x30Jk04zKnkurNJeDnQXlShnLYo3t04BqR Qtycrcb1xSebfwmHBTD1P/678N9q0WKWOmarlKp17lNHXWYnXraRxCih6rVSFCTmioMr T3h60BZqLABeHQukLkH/tlP/PRq6yie0C4TqZf3ROE74mZuGkCIgpTy8VttvGjYAVnui y/aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=FhdIKnds; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r13-20020a05640251cd00b0045217702054si1142088edd.501.2022.09.20.16.22.36; Tue, 20 Sep 2022 16:23:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=FhdIKnds; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230283AbiITWyp (ORCPT + 99 others); Tue, 20 Sep 2022 18:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiITWyk (ORCPT ); Tue, 20 Sep 2022 18:54:40 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 881595F6F; Tue, 20 Sep 2022 15:54:38 -0700 (PDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28KLwIIA003520; Tue, 20 Sep 2022 22:54:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=oYK6TumnSDP79KmzKKCHc3Thiq4B9cnHKK0N6TQXz+s=; b=FhdIKnds4/ao8gluJUUTb1j643R16U4ZzzCFuEBzbK7q6NgHDgVAroZPWoPcAAThYSML YTOUFMWJUKh2Xx6aa+U97kABfaNJniT9+Hg4ii5FZpa7/ncXhqmxY01o8GjNxOjShbyF u7uZ4xIybt7enlNpbzXt+H7SxDbxOX8thC93Cdrq2tNtLMOPRrN0pJbuKjfbTNVr4khE UE2NYYRWSKI+rbaJF66rY1NohczIcFh9YUc3+ycqDud4stskYZYuh3sZgPJipboeLkvJ RTU29ZkRF8+1MSlkLzKXcishroFxyuv+wHvmF/+ATYatmaRTxhzZoUs5h01R9LYI7yLI Hw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jqnsba0x9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Sep 2022 22:54:20 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 28KMluq0007777; Tue, 20 Sep 2022 22:54:19 GMT Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jqnsba0wu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Sep 2022 22:54:19 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28KMsIhI028635; Tue, 20 Sep 2022 22:54:18 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma02dal.us.ibm.com with ESMTP id 3jn5v9v3ew-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Sep 2022 22:54:18 +0000 Received: from smtpav03.wdc07v.mail.ibm.com ([9.208.128.112]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28KMrobw63308110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Sep 2022 22:53:51 GMT Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A2D8758054; Tue, 20 Sep 2022 22:53:50 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A61E35805D; Tue, 20 Sep 2022 22:53:49 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.ibm.com (unknown [9.160.97.163]) by smtpav03.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Sep 2022 22:53:49 +0000 (GMT) Message-ID: <2ee1e3e68d847001c4bf856d980a553e52de5023.camel@linux.ibm.com> Subject: Re: [PATCH] KEYS: encrypted: fix key instantiation with user-provided data From: Mimi Zohar To: Nikolaus Voss Cc: David Howells , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Yael Tzur Date: Tue, 20 Sep 2022 18:53:49 -0400 In-Reply-To: <35fd816-d755-967-5712-b5496875ac7a@vosn.de> References: <20220919072317.E41421357@mail.steuer-voss.de> <53730789a41358673b1715dd650706e9ffcb1199.camel@linux.ibm.com> <35fd816-d755-967-5712-b5496875ac7a@vosn.de> Content-Type: text/plain; charset="ISO-8859-15" X-Mailer: Evolution 3.28.5 (3.28.5-18.el8) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: sMx5z6293e_ehcWEkD1Jlqlmse1KmUDC X-Proofpoint-ORIG-GUID: _UECJhX_Ua7HB6pA3Bmwjo68ZckAq3up X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-20_10,2022-09-20_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209200137 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2022-09-20 at 18:23 +0200, Nikolaus Voss wrote: > On Tue, 20 Sep 2022, Mimi Zohar wrote: > > On Fri, 2022-09-16 at 07:45 +0200, Nikolaus Voss wrote: > >> Commit cd3bc044af48 ("KEYS: encrypted: Instantiate key with user-provided > >> decrypted data") added key instantiation with user provided decrypted data. > >> The user data is hex-ascii-encoded but was just memcpy'ed to the binary buffer. > >> Fix this to use hex2bin instead. > > > > Thanks, Nikolaus. We iterated a number of times over what would be the > > safest userspace input. One of the last changes was that the key data > > should be hex-ascii-encoded. Unfortunately, the LTP > > testcases/kernel/syscalls/keyctl09.c example isn't hex-ascii-encoded > > and the example in Documentation/security/keys/trusted-encrypted.rst > > just cat's a file. Both expect the length to be the length of the > > userspace provided data. With this patch, when hex2bin() fails, there > > is no explanation. > > That's true. But it's true for all occurrences of hex2bin() in this file. > I could pr_err() an explanation, improve the trusted-encrypted.rst example > and respin the patch. Should I, or do you have another suggestion? > I wasn't aware of keyctl09.c, but quickly looking into it, the user data > _is_ hex-ascii-encoded, only the length is "wrong": Imho, the specified > length should be the binary length as this is consistent with key-length > specs in other cases (e.g. when loading the key from a blob). > keyctl09.c could be easy to fix, if only the length is modified. Should > I propose a patch? What is the correct/appropriate workflow there? I'm concerned that this change breaks existing encrypted keys created with user-provided data. Otherwise I'm fine with your suggestion. The LTP example decrypted data length is 32, but the minimum decrypted data size is 20. So it's a bit more than just changing the LTP decrypted data size. The modified LTP test should work on kernels with and without this patch. -- thanks, Mimi