Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp686874lqb; Fri, 15 Mar 2024 03:49:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5EofZx+Cj3vM81yBRrZ/96Bz+y/h6H19vnXr4Z8k1Vd/crY9irahu3tV2eQVqIY4uon2SwfYu3SaoSJAPU94H4PcnWbPJF3ZLWkjZtg== X-Google-Smtp-Source: AGHT+IH6VsWCBUVwpzuZ8Tz3lBvU4gHCMDEoWIlbIlDYxi+Y3qCv3kB2fVbi6lUAXCq+QzAttdcU X-Received: by 2002:a81:a001:0:b0:609:ee9d:d823 with SMTP id x1-20020a81a001000000b00609ee9dd823mr4714423ywg.20.1710499755341; Fri, 15 Mar 2024 03:49:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710499755; cv=pass; d=google.com; s=arc-20160816; b=0/EH1Su6plGB6AdUnBH0+nDctnOvrjk6fUL6AtM7b2qCKDchiU0hakoz/hdPxxXYfl wbIfXxmTftgZxzBUDeovCP++jh9IerGA9tRpFXBGViHhVEEv4ATkGBrt421MrvQh7Q6w 1xCfHU2osfpr2VGIWgiCCBa8lzcSLvQre6X4QpzwpVGybUp68nteWa9uqpceaq6cDYZC Xyghh2bo0kcFEqX+tbTHpnJZIBIKd4DUYqYDb3JyrIhp5vxcFD788GYc1faTXyoijKgl t4Mrls8SjdwbSLDHq61mKdd2ycc3ReVurtZ4Z5sbD8rwiwyoJ102i+gBP4l2HZlftRJf z3fg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=P7tMfoPNeOt/+PX7moX01B7+3/zv3ABtNf3HJ7mmSpU=; fh=/Zt/T+n0R6ZuUQzhSWwosapG0GVQL6tHkgbc1VRIyvo=; b=CsMfXkSFMrC5JJY7Hqk6/MvA13i9sAwD7L0bh3DPZ80Hn7I6lUsdz8k1WiGfMP/ZJB pd3DQBMSlH80VPGp6KXEw5IRyOZuSNLgjwx00TzBi1TNI36MxJ42BPnWVZWBLUgAFuSS V1N0Qc/KCr9BeJyGBRzYMirQcci3k5KKfTUlB3kFOUqpqF76m0Riwn0OvIcFZMlFrqAg r3CioLu4r40wH8cdXke8JXHgk/QKNTX6Zf+MtZ8alEMiTcPf1QO3r5JizpW/Bm603WkV M3bBy/nVLPeImD0CNGhuA91sH1EhJpZ74ho69agVlAQk1pDoYg3iWi+ihG5NHvi/PUBJ MGpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-crypto+bounces-2687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2687-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bp13-20020a05622a1b8d00b00430978eb3bdsi3372564qtb.570.2024.03.15.03.49.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 03:49:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-crypto+bounces-2687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2687-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 137BE1C21D32 for ; Fri, 15 Mar 2024 10:49:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED38619470; Fri, 15 Mar 2024 10:49:11 +0000 (UTC) X-Original-To: linux-crypto@vger.kernel.org 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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:". */ -- 2.34.1