From patchwork Fri Mar 15 10:33:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Smirnov X-Patchwork-Id: 780782 Received: from mx01.omp.ru (mx01.omp.ru [90.154.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E032917C6A; Fri, 15 Mar 2024 10:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.154.21.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710499751; cv=none; b=YLSH3I94TcXTw8XAY8rlkU0W9cVU0OCQa1BEYCQzxPI6v2f9l0KSQiTBB7jBxIhC8FBEFiSqU6Ixn7+MhFkY9AhcHu3EQYBPXuHlp5moHZ/HrrgH0xL3h2uoGl6MjVDx0U8bpl+3IL8IZsKYwC8VcvuQJJOk1DRk64GhdtTXpSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710499751; c=relaxed/simple; bh=jivNuqXQZCWLHn2VX0XziwfCEypg4DNg5PJ4X9qRCeI=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=IUtIVbb6O4ox/p/wfXSNz8qcV32ciXQ7pgUy7q0x1R3m3DlrH5fMUpRsCI9YczBknX2UMCMy/IeE72AWRL1lh4/r38D94oxTNmHO8GwuBGq8wstTg93JDfHGsSKIILXtE5E0+ubtDe4PRvWP6++Eg5d8hg+QNT7Ef4pWk9UBaVI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru; spf=pass smtp.mailfrom=omp.ru; arc=none smtp.client-ip=90.154.21.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=omp.ru Received: from localhost.localdomain (78.37.41.175) by msexch01.omp.ru (10.188.4.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1258.12; Fri, 15 Mar 2024 13:33:49 +0300 From: Roman Smirnov To: David Howells , Herbert Xu , "David S. Miller" , Jarkko Sakkinen , Andrew Zaborowski CC: Roman Smirnov , , , , , Sergey Shtylyov Subject: [PATCH] KEYS: prevent NULL pointer dereference in find_asymmetric_key() Date: Fri, 15 Mar 2024 13:33:20 +0300 Message-ID: <20240315103320.18754-1-r.smirnov@omp.ru> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: msexch01.omp.ru (10.188.4.12) To msexch01.omp.ru (10.188.4.12) X-KSE-ServerInfo: msexch01.omp.ru, 9 X-KSE-AntiSpam-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 6.1.0, Database issued on: 03/15/2024 10:13:53 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 59 X-KSE-AntiSpam-Info: Lua profiles 184188 [Mar 15 2024] X-KSE-AntiSpam-Info: Version: 6.1.0.4 X-KSE-AntiSpam-Info: Envelope from: r.smirnov@omp.ru X-KSE-AntiSpam-Info: LuaCore: 10 0.3.10 53c821b925e16276b831986eabc71d60ab82ee60 X-KSE-AntiSpam-Info: {rep_avail} X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: {relay has no DNS name} X-KSE-AntiSpam-Info: {SMTP from is not routable} X-KSE-AntiSpam-Info: d41d8cd98f00b204e9800998ecf8427e.com:7.1.1; omp.ru:7.1.1; 127.0.0.199:7.1.2; 78.37.41.175:7.1.2 X-KSE-AntiSpam-Info: ApMailHostAddress: 78.37.41.175 X-KSE-AntiSpam-Info: {DNS response errors} X-KSE-AntiSpam-Info: Rate: 59 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-AntiSpam-Info: Auth:dmarc=temperror header.from=omp.ru;spf=temperror smtp.mailfrom=omp.ru;dkim=none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Heuristic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 03/15/2024 10:18:00 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 3/15/2024 6:29:00 AM X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit With the current code, in case all NULLs are passed in id_{0,1,2}, the kernel will first print out a WARNING and then have an oops because id_2 gets dereferenced anyway. Note that WARN_ON() is also considered harmful by Greg Kroah- Hartman since it causes the Android kernels to panic as they get booted with the panic_on_warn option. Found by Linux Verification Center (linuxtesting.org) with Svace. Fixes: 7d30198ee24f ("keys: X.509 public key issuer lookup without AKID") Suggested-by: Sergey Shtylyov Signed-off-by: Roman Smirnov Reviewed-by: Sergey Shtylyov --- crypto/asymmetric_keys/asymmetric_type.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c index a5da8ccd353e..f5cbd6ff14e2 100644 --- a/crypto/asymmetric_keys/asymmetric_type.c +++ b/crypto/asymmetric_keys/asymmetric_type.c @@ -60,17 +60,17 @@ struct key *find_asymmetric_key(struct key *keyring, char *req, *p; int len; - WARN_ON(!id_0 && !id_1 && !id_2); - if (id_0) { lookup = id_0->data; len = id_0->len; } else if (id_1) { lookup = id_1->data; len = id_1->len; - } else { + } else if (id_2) { lookup = id_2->data; len = id_2->len; + } else { + return ERR_PTR(-EINVAL); } /* Construct an identifier "id:". */