Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp362647img; Tue, 26 Feb 2019 01:09:44 -0800 (PST) X-Google-Smtp-Source: AHgI3IZOC7qJNcAQ8+mU/K8yHtBIcRyVn9pgVHT4q8artlO/1fX86ydanh+OqeQ3ogumIGPKpXlb X-Received: by 2002:a62:57dd:: with SMTP id i90mr25040821pfj.154.1551172183757; Tue, 26 Feb 2019 01:09:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551172183; cv=none; d=google.com; s=arc-20160816; b=D8D8MC1NLxMrU314ujwj2Zhx7xy7hTSpZvjrhimP9qgomQvhGYiObAEHlS3JOeNCPv O+VEHS4jQwEa8Qxu/VLYX8t+j3tRE6vOAQp2p3u1gtArL2OYXi3c9xo5Avjm1Rs0RckZ sNHY78RROezYPOt0mKFFvDzDu3MQ/a3UjJ30I4jUtcFhYe+dHb8UhCJafdqmDO4Bnocg AKD8/V2a7tlhiFzPQBUlEEYWk54SValTv1bhs/2fYGcpPkYVjAK0w0djoaGsvr2ckXp1 dHBsPHcSehztWZGsmpQVuCxAx2npSFAmHhfXWr6WYS+TBuv8G0ei4AQzGmak5dxHTDIr t+Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=52U25cht0zHiNRNh66FwIqUZB8W16/yFRaq8MAGOCOU=; b=u0H5bL24aqg5VNXyQs8eBVnzsa2gcHsln4RMVhO8EB04+OfGMp5/sYurww3VkLcB75 IP+PaJtYVKEoOBpTCLJI+sAWkzdYRDcUNngnO1YRfr7Qvxg97UY1zKdjaoYB85O0ECRv /DVLaZfoQczGb69apFG9OVZxJXCAlU8QpV1N5BHMNp1H6vD28x0gNzE10kaxTwWYH70i 05RGklOPV6pkuC7MWcWXcqJAqCtVhWlA90yITd5ggWWNcJc2TYIRWXPIFhLkCd9YCcIM DDAJTcmN+tfD2DyH6by45WqOUY3iZVjoJCC9HycmNU/Hpr0rCnvGcg6xRJLxmwD+fSVY FfAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pCQTUdVX; 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 d188si10911904pgc.97.2019.02.26.01.09.28; Tue, 26 Feb 2019 01:09:43 -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=pCQTUdVX; 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 S1727435AbfBZJJH (ORCPT + 99 others); Tue, 26 Feb 2019 04:09:07 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36760 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727135AbfBZJJG (ORCPT ); Tue, 26 Feb 2019 04:09:06 -0500 Received: by mail-pg1-f195.google.com with SMTP id r124so5920688pgr.3; Tue, 26 Feb 2019 01:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=52U25cht0zHiNRNh66FwIqUZB8W16/yFRaq8MAGOCOU=; b=pCQTUdVXRjdN2oHcSwJV1KFOqwZqKklngD75ks+Uu9IwXl5ZuHSmuqanlhvIyX9wjY p/MthjObBgkzoiZNpZ17efB7XfFcU+mf/wW7H6AkzGGsCV+6HKw4/4BawF27dhEuUBhu F8eqprbPejNaSyGY3NCICTrHmIx1fFAOqtMF0VuzzAEPUlriiOgmSLcZTwr3TN7JGs1f LmAgdLm7f7IP5bUoukLsCu0H8MSZaB7DuYsZAnV+pLxQNItI+CE8lx2uuLmrDBoeqIL8 T/tLZJrfPeJlhhr1ybpSoaIs5tdJVUIAqvNa1f3RaPr5ix6RIpooaULY7Ozj+jTFAu2M uKgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=52U25cht0zHiNRNh66FwIqUZB8W16/yFRaq8MAGOCOU=; b=HQfPd9tYw7bLBttM8gHLjHT9HHJ+JPMovb1tEI5ek1PmPf9rr9qmVNrX2dYjblh6zX kDsK2nMWjdSDn9NFdv9m8+5X22OxhOkTgqkvTNwIcemVyQu5KhzdhUoDDwQJawUOCQSO 3LPdVcLbaRlAUn12Vv+zhxzrfRn4ojCQA94nYtHOhhpj9e7ANEV+RybX4CKIvNNlnAOp Ffqcsc00UQDN9o/Yn676E+mZoD6YfHrt6IxBHlokOw7BDkU7r5Fow0GF9jDC+v1dgoGb B2geKdL+ZxJ3yesyBGUzkpOqR7EUUryS1tm1LGhzP7OudrbCWQ3pQh8KKeTObZ5oh32u myzg== X-Gm-Message-State: AHQUAuZkA6Yb1S0AD1hj17bbvuO+fMcvM9bCWQDW1YP3IUZ0vxN/2njX Dlb4dkrNVOjRpwmEr73agaw= X-Received: by 2002:a65:4147:: with SMTP id x7mr2711647pgp.54.1551172145673; Tue, 26 Feb 2019 01:09:05 -0800 (PST) Received: from localhost ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id q5sm18093662pga.71.2019.02.26.01.09.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Feb 2019 01:09:05 -0800 (PST) Date: Tue, 26 Feb 2019 17:09:03 +0800 From: Geliang Tang To: David Howells , James Morris , "Serge E. Hallyn" Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] security: keys: add NULL checking for key->type->instantiate Message-ID: <20190226090903.GA3197@OptiPlex> References: <754d6ccb4012fc11c7b9369e66ba7f3e816fdb57.1548400400.git.geliangtang@gmail.com> <31395.1549492013@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <31395.1549492013@warthog.procyon.org.uk> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 06, 2019 at 10:26:53PM +0000, David Howells wrote: > Geliang Tang wrote: > > > key->type->instantiate can be NULL, add NULL checking to prevent > > NULL pointer dereference in __key_instantiate_and_link(). > > Do you have an oops report or test case for this? > > David Here is the test module code. Insmod it, we can get the oops. #include #include #include #include #include #include static int test_instantiate(struct key *key, struct key_preparsed_payload *prep) { return 0; } static void test_describe(const struct key *key, struct seq_file *m) { seq_puts(m, key->description); } struct key_type test_key_type = { .name = "test", //.instantiate = test_instantiate, .describe = test_describe, }; static int __init test_init(void) { const struct cred *cred = current_cred(); struct key *key; int ret; register_key_type(&test_key_type); key = key_alloc(&test_key_type, "test", GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, cred, KEY_POS_SEARCH, KEY_ALLOC_NOT_IN_QUOTA, NULL); if (IS_ERR(key)) return -1; pr_info("keyring allocated successfully.\n"); ret = key_instantiate_and_link(key, NULL, sizeof(int), current->cred->user->session_keyring, NULL); if (ret < 0) { key_revoke(key); key_put(key); return ret; } return 0; } static void __exit test_exit(void) { unregister_key_type(&test_key_type); } module_init(test_init); module_exit(test_exit); MODULE_LICENSE("GPL");