Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp151585imu; Thu, 24 Jan 2019 23:18:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN5VxGbPqphQ+RM6+MlFHfOrebMrLCqyIoiYOghEnmC0irWRN8Pn6pVIUlWvNTGQL9MskJ07 X-Received: by 2002:a63:1321:: with SMTP id i33mr9060490pgl.380.1548400728894; Thu, 24 Jan 2019 23:18:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548400728; cv=none; d=google.com; s=arc-20160816; b=HllhJwLsON5IwYo84HAESmulAzORLw3JaSO+CgSIFKCJlyLAA3AsOTmm3J+NwccZ1A 01N16Nd62ZlVnRC4zsFxNdEzynwZdqCkohyz68/As2hCfwgZsSYbd6qJ4c9qOwC74toh YNWyWp/RxqI3lvbGswPqP6AHwvcAiplXAq+ID2Tx3Td4s64RsZrMbV+SFq46FQ4FGOzk ivLRZ4mScT9bybvMc5A2UBtcghtCW7g87X2Q00+eeD9Gpm3ob8zC3LKO8k7jO+PzI9/I 27veX/FFJYM/AZaOIUgqyPqz+BMiRmXfiKyeJqz3PyroYIZIL3YNUYeCd21XJlWWObwu PnGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=9GVpEo5LqrgwqJj+OhnBHVqnVwMlvZt3InuYblIl+j4=; b=FpDb72zmPJPuZPrjUjZN5hCxrcMbMan58+/kJyHIMoDrfRbQ4dWj4LXKA3HMhXzvL0 /pWZf37n4sxIB3+FI8CUMgSj2CQydZ2pze2CCEd0j055FIshs6aZYv4v9sGOyUMSIKBr PsSc+5/0n4hfhgkbezRK1C9bkw/vluSiGWt3iCSVRS9V/mnIgnHAjaHhTNB1m2fIkNaX 5pZE2nTeZlziVOwvvMRs1qOdD/sA9WZjekZguvt/XmjEfZNOXJTaSBxeWv22KNpzVnVh A8b64b/GSARKLkC87H/LnNC46uLFRLpq+OWp3UcaqysMhMzCeHq+3UXrx5viYwNOVi9V Yctg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CwHCIeZh; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j195si26567871pfd.165.2019.01.24.23.18.33; Thu, 24 Jan 2019 23:18:48 -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=@gmail.com header.s=20161025 header.b=CwHCIeZh; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728047AbfAYHQn (ORCPT + 99 others); Fri, 25 Jan 2019 02:16:43 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35842 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbfAYHQm (ORCPT ); Fri, 25 Jan 2019 02:16:42 -0500 Received: by mail-pg1-f193.google.com with SMTP id n2so3845505pgm.3; Thu, 24 Jan 2019 23:16:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=9GVpEo5LqrgwqJj+OhnBHVqnVwMlvZt3InuYblIl+j4=; b=CwHCIeZhlXvrNF+ilBf+cJ5FmkD549IOyHAGVg2WOizcZq2ZaOLxC9YnpuLml01iXi kNyawF1dzltSA8aRwxCWqgO8Nr/RjoXQFQHU3g6kdVsIY1jQiN1LKypBBw+OZ0/CgU4E 0QhLum3cCalZQ57JCAI416+0P5dFcs0H1hpwaaHwW4oa5Wn2L1h2dO1fz+Pm1zO9pZrt HK3ZJPZjGjZHnoY3LXHWKNafvcR1oWyJDHnRJtvfQTyjlydvv2SuYsX3d7fRJZomTF6O WB3vudJLz+sNjNlxlRT+KAhlNSqGPunj5zLRuGconlV8/he/IqXkd1uvryYJRP9/X0e+ UN+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=9GVpEo5LqrgwqJj+OhnBHVqnVwMlvZt3InuYblIl+j4=; b=XW/I0aBRkUlS8sOxY2HcGJWChSJy/p4rhQJBBItpxnInkTBfQdPx+V+cA6W+vSbLHj MrEeTRBneCd6K9E4YKuQl8RhZEHyGsU4qa1GL+cyOFe3bUuVF7PRpepaEZgXL7NMcWpp 6ZL2UDLZCatecrmLBGpXJ9OATCQE0rI91o+goiwoF1ZoIUwKuJiCnJrpIH3k2g4Qvott zy+5IrvSUm7uwER1FY5uL+RnJcZhZDu1O/VQG5sLanBdUpfk6Vdr9gPhf8CySUztjmtw halhK9OGokj2PKiuI3GWy5SJtngFPt2UdGKhiZj4vyn1thfb447eryOV4j+c1HI8X7Iz BYBA== X-Gm-Message-State: AJcUukcVicqd2StHpcY4VGBUr4ipCju0qhiuXaXrTmcdydrrGbOtj+hU sMy8t0iEmeKDjVUCnO8D/5M= X-Received: by 2002:a63:fa58:: with SMTP id g24mr8739439pgk.390.1548400601982; Thu, 24 Jan 2019 23:16:41 -0800 (PST) Received: from localhost ([43.224.245.181]) by smtp.gmail.com with ESMTPSA id p7sm34241321pfa.22.2019.01.24.23.16.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Jan 2019 23:16:40 -0800 (PST) From: Geliang Tang To: David Howells , James Morris , "Serge E. Hallyn" Cc: Geliang Tang , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] security: keys: add NULL checking for key->type->instantiate Date: Fri, 25 Jan 2019 15:16:14 +0800 Message-Id: <754d6ccb4012fc11c7b9369e66ba7f3e816fdb57.1548400400.git.geliangtang@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org key->type->instantiate can be NULL, add NULL checking to prevent NULL pointer dereference in __key_instantiate_and_link(). Signed-off-by: Geliang Tang --- security/keys/key.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/security/keys/key.c b/security/keys/key.c index 44a80d6741a1..ae3cc11be0d2 100644 --- a/security/keys/key.c +++ b/security/keys/key.c @@ -438,7 +438,8 @@ static int __key_instantiate_and_link(struct key *key, /* can't instantiate twice */ if (key->state == KEY_IS_UNINSTANTIATED) { /* instantiate the key */ - ret = key->type->instantiate(key, prep); + if (key->type->instantiate) + ret = key->type->instantiate(key, prep); if (ret == 0) { /* mark the key as being instantiated */ -- 2.17.1