linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Matthew Garrett <matthewgarrett@google.com>, jmorris@namei.org
Cc: linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	Matthew Garrett <mjg59@google.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Krzysztof Kozlowski <krzk@kernel.org>
Subject: Re: [PATCH V37 27/29] tracefs: Restrict tracefs when the kernel is locked down
Date: Tue, 13 Aug 2019 09:21:09 +0200	[thread overview]
Message-ID: <3028ed35-3b6d-459f-f3c8-103c5636fe95@samsung.com> (raw)
In-Reply-To: <a3caa6d3-e3f9-ae41-d87e-253d9dc53d81@samsung.com>

Hi again,

On 2019-08-13 08:10, Marek Szyprowski wrote:
> Hi
>
> On 2019-08-01 00:16, Matthew Garrett wrote:
>> Tracefs may release more information about the kernel than desirable, so
>> restrict it when the kernel is locked down in confidentiality mode by
>> preventing open().
>>
>> Signed-off-by: Matthew Garrett <mjg59@google.com>
>> Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
>
> This patch causes the following regression on various Samsung Exynos 
> SoC based boards (ARM 32bit):
>
> [   15.364422] Unable to handle kernel NULL pointer dereference at 
> virtual address 00000000
> [   15.368775] pgd = a530ddbe
> [   15.371447] [00000000] *pgd=bcd7c831
> [   15.374993] Internal error: Oops: 80000007 [#1] PREEMPT SMP ARM
> [   15.380890] Modules linked in:
> [   15.383929] CPU: 0 PID: 1393 Comm: perf Not tainted 
> 5.2.0-00027-g757ff7244358-dirty #6459
> [   15.392086] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
> [   15.398164] PC is at 0x0
> [   15.400687] LR is at do_dentry_open+0x22c/0x3b0
> [   15.405193] pc : [<00000000>]    lr : [<c02977c4>]    psr: 60000053
> [   15.411442] sp : e7317dd8  ip : 00000000  fp : 00000000
> [   15.416650] r10: c0187e6c  r9 : c041f8cc  r8 : e72123c8
> [   15.421858] r7 : e7317ec0  r6 : e7d89630  r5 : 00000000  r4 : e72123c0
> [   15.428368] r3 : 00000000  r2 : 5ba370f3  r1 : e72123c0  r0 : e7d89630
> [   15.434880] Flags: nZCv  IRQs on  FIQs off  Mode SVC_32  ISA ARM  
> Segment none
> [   15.442083] Control: 10c5387d  Table: 6726404a  DAC: 00000051
> [   15.447812] Process perf (pid: 1393, stack limit = 0x17621431)
> [   15.453628] Stack: (0xe7317dd8 to 0xe7318000)
> ...
> [   15.604842] [<c02977c4>] (do_dentry_open) from [<c02aafc8>] 
> (path_openat+0x5a0/0x1004)
> [   15.612735] [<c02aafc8>] (path_openat) from [<c02acce8>] 
> (do_filp_open+0x6c/0xd8)
> [   15.620200] [<c02acce8>] (do_filp_open) from [<c0298cc4>] 
> (do_sys_open+0x130/0x1f4)
> [   15.627839] [<c0298cc4>] (do_sys_open) from [<c0101000>] 
> (ret_fast_syscall+0x0/0x28)
> [   15.635560] Exception stack(0xe7317fa8 to 0xe7317ff0)
> [   15.640596] 7fa0:                   0022dc0b 001deee0 ffffff9c 
> beb6d764 00020000 00000000
> [   15.648756] 7fc0: 0022dc0b 001deee0 0022dba8 00000142 001ba044 
> 00241d68 001a13d8 beb6e78c
> [   15.656913] 7fe0: b6f7e000 beb6c6f8 9a27c600 b6f69504
> [   15.661952] Code: bad PC value
> [   15.665105] ---[ end trace 7e8b864582108f4a ]---
>
> This is standard ARM 32bit kernel with 
> arch/arm/configs/exynos_defconfig. It is enough to run "perf list" 
> command.
>
>> ---
>>   fs/tracefs/inode.c           | 40 +++++++++++++++++++++++++++++++++++-
>>   include/linux/security.h     |  1 +
>>   security/lockdown/lockdown.c |  1 +
>>   3 files changed, 41 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
>> index 1387bcd96a79..12a325fb4cbd 100644
>> --- a/fs/tracefs/inode.c
>> +++ b/fs/tracefs/inode.c
>> @@ -21,6 +21,7 @@
>>   #include <linux/seq_file.h>
>>   #include <linux/magic.h>
>>   #include <linux/slab.h>
>> +#include <linux/security.h>
>>     #define TRACEFS_DEFAULT_MODE    0700
>>   @@ -28,6 +29,23 @@ static struct vfsmount *tracefs_mount;
>>   static int tracefs_mount_count;
>>   static bool tracefs_registered;
>>   +static int default_open_file(struct inode *inode, struct file *filp)
>> +{
>> +    struct dentry *dentry = filp->f_path.dentry;
>> +    struct file_operations *real_fops;
>> +    int ret;
>> +
>> +    if (!dentry)
>> +        return -EINVAL;
>> +
>> +    ret = security_locked_down(LOCKDOWN_TRACEFS);
>> +    if (ret)
>> +        return ret;
>> +
>> +    real_fops = dentry->d_fsdata;
>
> real_fops are NULL in my test case.

Too much of a hurry. real_fops are okay in that test case...

>
>> +    return real_fops->open(inode, filp);

... the issue is caused by NULL ->open() callback. Switching the above 
line to:

return real_fops->open ? real_fops->open(inode, filp) : 0;

fixes the issue.

>> +}
>> +
>>   static ssize_t default_read_file(struct file *file, char __user *buf,
>>                    size_t count, loff_t *ppos)
>>   {
>> @@ -210,6 +228,12 @@ static int tracefs_apply_options(struct 
>> super_block *sb)
>>       return 0;
>>   }
>>   +static void tracefs_destroy_inode(struct inode *inode)
>> +{
>> +    if (S_ISREG(inode->i_mode))
>> +        kfree(inode->i_fop);
>> +}
>> +
>>   static int tracefs_reconfigure(struct fs_context *fc)
>>   {
>>       struct super_block *sb = fc->root->d_sb;
>> @@ -236,6 +260,7 @@ static int tracefs_show_options(struct seq_file 
>> *m, struct dentry *root)
>>     static const struct super_operations tracefs_super_operations = {
>>       .statfs        = simple_statfs,
>> +    .destroy_inode  = tracefs_destroy_inode,
>>       .show_options    = tracefs_show_options,
>>   };
>>   @@ -372,6 +397,7 @@ struct dentry *tracefs_create_file(const char 
>> *name, umode_t mode,
>>                      struct dentry *parent, void *data,
>>                      const struct file_operations *fops)
>>   {
>> +    struct file_operations *proxy_fops;
>>       struct dentry *dentry;
>>       struct inode *inode;
>>   @@ -387,8 +413,20 @@ struct dentry *tracefs_create_file(const char 
>> *name, umode_t mode,
>>       if (unlikely(!inode))
>>           return failed_creating(dentry);
>>   +    proxy_fops = kzalloc(sizeof(struct file_operations), GFP_KERNEL);
>> +    if (unlikely(!proxy_fops)) {
>> +        iput(inode);
>> +        return failed_creating(dentry);
>> +    }
>> +
>> +    if (!fops)
>> +        fops = &tracefs_file_operations;
>> +
>> +    dentry->d_fsdata = (void *)fops;
>> +    memcpy(proxy_fops, fops, sizeof(*proxy_fops));
>> +    proxy_fops->open = default_open_file;
>>       inode->i_mode = mode;
>> -    inode->i_fop = fops ? fops : &tracefs_file_operations;
>> +    inode->i_fop = proxy_fops;
>>       inode->i_private = data;
>>       d_instantiate(dentry, inode);
>>       fsnotify_create(dentry->d_parent->d_inode, dentry);
>> diff --git a/include/linux/security.h b/include/linux/security.h
>> index d92323b44a3f..807dc0d24982 100644
>> --- a/include/linux/security.h
>> +++ b/include/linux/security.h
>> @@ -121,6 +121,7 @@ enum lockdown_reason {
>>       LOCKDOWN_KPROBES,
>>       LOCKDOWN_BPF_READ,
>>       LOCKDOWN_PERF,
>> +    LOCKDOWN_TRACEFS,
>>       LOCKDOWN_CONFIDENTIALITY_MAX,
>>   };
>>   diff --git a/security/lockdown/lockdown.c 
>> b/security/lockdown/lockdown.c
>> index 88064ce1c844..173191562047 100644
>> --- a/security/lockdown/lockdown.c
>> +++ b/security/lockdown/lockdown.c
>> @@ -36,6 +36,7 @@ static char 
>> *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
>>       [LOCKDOWN_KPROBES] = "use of kprobes",
>>       [LOCKDOWN_BPF_READ] = "use of bpf to read kernel RAM",
>>       [LOCKDOWN_PERF] = "unsafe use of perf",
>> +    [LOCKDOWN_TRACEFS] = "use of tracefs",
>>       [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality",
>>   };
>
> Best regards

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


  parent reply	other threads:[~2019-08-13  7:21 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-31 22:15 [PATCH V37 00/29] security: Add support for locking down the kernel Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 01/29] security: Support early LSMs Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 02/29] security: Add a "locked down" LSM hook Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 03/29] security: Add a static lockdown policy LSM Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 04/29] Enforce module signatures if the kernel is locked down Matthew Garrett
2019-08-01 14:21   ` Jessica Yu
2019-08-01 20:42     ` Matthew Garrett
2019-08-08 10:01       ` Jessica Yu
2019-08-08 18:31         ` Matthew Garrett
2019-08-08 22:43           ` James Morris
2019-08-09 20:59         ` [PATCH V39] " Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 05/29] Restrict /dev/{mem,kmem,port} when " Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 06/29] kexec_load: Disable at runtime if " Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 07/29] Copy secure_boot flag in boot params across kexec reboot Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 08/29] kexec_file: split KEXEC_VERIFY_SIG into KEXEC_SIG and KEXEC_SIG_FORCE Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 09/29] kexec_file: Restrict at runtime if the kernel is locked down Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 10/29] hibernate: Disable when " Matthew Garrett
2019-07-31 22:15 ` [PATCH V37 11/29] PCI: Lock down BAR access " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 12/29] x86: Lock down IO port " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 13/29] x86/msr: Restrict MSR " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 14/29] ACPI: Limit access to custom_method " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 15/29] acpi: Ignore acpi_rsdp kernel param when the kernel has been " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 16/29] acpi: Disable ACPI table override if the kernel is " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 17/29] Prohibit PCMCIA CIS storage when " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 18/29] Lock down TIOCSSERIAL Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 19/29] Lock down module params that specify hardware parameters (eg. ioport) Matthew Garrett
2019-08-01 16:19   ` Jessica Yu
2019-08-01 20:44     ` Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 20/29] x86/mmiotrace: Lock down the testmmiotrace module Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 21/29] Lock down /proc/kcore Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 22/29] Lock down tracing and perf kprobes when in confidentiality mode Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 23/29] bpf: Restrict bpf when kernel lockdown is " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 24/29] Lock down perf when " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 25/29] kexec: Allow kexec_file() with appropriate IMA policy when locked down Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 26/29] debugfs: Restrict debugfs when the kernel is " Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 27/29] tracefs: Restrict tracefs " Matthew Garrett
     [not found]   ` <CGME20190813061053eucas1p1b6945259d9663b743e7cb32521d041e7@eucas1p1.samsung.com>
2019-08-13  6:10     ` Marek Szyprowski
     [not found]       ` <CGME20190813072111eucas1p2b87f3f8d16c22a0a3d024bc5ebcc8bcc@eucas1p2.samsung.com>
2019-08-13  7:21         ` Marek Szyprowski [this message]
     [not found]           ` <CGME20190814061246eucas1p128cae99a14f27bc79fa2aa72084a0413@eucas1p1.samsung.com>
2019-08-14  6:12             ` [PATCH] tracefs: Fix NULL pointer dereference when no lockdown is used Marek Szyprowski
2019-07-31 22:16 ` [PATCH V37 28/29] efi: Restrict efivar_ssdt_load when the kernel is locked down Matthew Garrett
2019-07-31 22:16 ` [PATCH V37 29/29] lockdown: Print current->comm in restriction messages Matthew Garrett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3028ed35-3b6d-459f-f3c8-103c5636fe95@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=jmorris@namei.org \
    --cc=krzk@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=matthewgarrett@google.com \
    --cc=mjg59@google.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).