Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp365452img; Tue, 26 Feb 2019 01:13:11 -0800 (PST) X-Google-Smtp-Source: AHgI3IZVpIpBcPv2YsM0bdYbl7LGIMMgi2ir1Zrnva5ulwEYjCGInh872DJjrHNGUUmtIJnSIQwU X-Received: by 2002:a17:902:7293:: with SMTP id d19mr24245641pll.29.1551172391346; Tue, 26 Feb 2019 01:13:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551172391; cv=none; d=google.com; s=arc-20160816; b=k8xhyM+l3HtmK7XJg2OmpYCDqmWqG74F4Pm2g0Zo69GUUVyckIWk5sOde9YIC1PMem P0LB6SZM3CZIyvXbTwWry35y3vzHQ/Eyg8yv0Y2OEZC0b1XeW+cOHxOz8O4+GU4rS0OT FjKzrm5ebctUwQM9kO5TykVu3RBnaor96R/WeuX4UzS6ABnp4b2tsCCBytd4fqEeK0By FxQbgK36F44KOt5RlKEUg8OzNbw6GrVXS4CK6I3qsda1nhrGSLsqD5pha1gzfxgWgBFk CjFZUzRp3xTo4Jub0YhRCoWkG9EcjGUvgQAITzctvPlk5jJPRPtTVEAGcWguiAtl1fh+ L+tw== 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=IhdAmOtbe8nPkcC9dZOBkdMqZYahxCQ54bupqq1vm/9TGf5+ynwH71kiWURlRBL3No Thir5yqiY632psi0fFur+jGtPjl9w3snEKqBgOP8yFN7YaIVb+1pAEWDqOOL2Scl+Y/k hQuNixstkCZ8CeJjeTxFmrb2irbMC2zyO9cAfCWU8PLFd83mBriZI5XJ00lY5ChJZarK flpvitJnsyf11h6W74PW/EHcWpI/hofyr3o2oUocxWGfXl5vynVF3kgm9EwSC71vVM4J IiTNe1U0WtnF32DG65ozgwoTGRzMfFsSbYBwbZu+hXvMkMOpyo8SHRqO0rtdTMpShz3H qwyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=brT4IZT4; 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 8si3119818pgq.591.2019.02.26.01.12.55; Tue, 26 Feb 2019 01:13:11 -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=brT4IZT4; 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 S1727446AbfBZJLV (ORCPT + 99 others); Tue, 26 Feb 2019 04:11:21 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44382 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbfBZJLV (ORCPT ); Tue, 26 Feb 2019 04:11:21 -0500 Received: by mail-pl1-f193.google.com with SMTP id c4so5917209pls.11; Tue, 26 Feb 2019 01:11:21 -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=brT4IZT49cG3cNpB34W0WTCGNNyWgaRmCghM7Ld5fwuKwmG2Q3ie1Ut9kNuiysILp8 EuWevQodHiQQDqme6eBezAluYSexQy/p31JYak1Ng/4RBIsT97Arl9sMxiU0Cr3vB8bV ip3iEsWEsV3hX+65RxMkO9Rm7m0Fbe+HvHnFC7DFkJ5ClaiVvVtS92yHJm7YgTXP/zym Hu80xzcJd9EucCvufczkTeCRuiuPonJMXCs9h8U93jVFTbXRr0yUsTKNDOhwK08hJ043 8zzTIaAGS5yVheDT5EUwKOwxZR5n1DPTvAGr6YY3x5RZRLt7NC9jqymckoqoOVzpluTI G4ug== 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=QUJKuRqI1f5PbDrzJibKCO8auguU9PfEysi5xthNRroHtsmLP9STyxnttTwNrp86Sj 3gkeWC5krAvMMaWgce7/HEvSrHheYDQm2/QZZBaQ4dH4uSO/z0R6mc1yZ2VVF1/8osKM POZgSGT5UbHiijCpoLue1panxVzgy3NzTQy5cxZuLCbG0rkVC8urHfUn216DiZwHHsJY WNKDIBNQG7xfQaLEdK8uzM35Bho1hvAbdqZsrOMcy6k6z+p/J7AR+UNdG0sbomsuZDFl bMv22stgzm/PAOtvJ6qCNQG9YRLSldrw1o89NAL6dU1riVqDUsPhJRDUkWP85sLT4Qkz P5KA== X-Gm-Message-State: AHQUAuaaihWqqSskbGvLJCJd5DTebZTXAfKmyQF7Ih+PvHiLDz3JtfNP XYgdky+t9Iw3FAlHbtRLaXtVVphu X-Received: by 2002:a17:902:5992:: with SMTP id p18mr25035122pli.231.1551172280717; Tue, 26 Feb 2019 01:11:20 -0800 (PST) Received: from localhost ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id f87sm268454pff.38.2019.02.26.01.11.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Feb 2019 01:11:20 -0800 (PST) Date: Tue, 26 Feb 2019 17:11:18 +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: <20190226091118.GB3197@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");