LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>,
	Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Dave Hansen <dave.hansen@intel.com>,
	Ying Huang <ying.huang@intel.com>,
	Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] mm, vmstat: Make sure mutex is a global static
Date: Tue, 7 Nov 2017 13:38:09 -0800
Message-ID: <20171107213809.GA4314@beast> (raw)

The mutex in sysctl_vm_numa_stat_handler() needs to be a global static, not
a stack variable, otherwise it doesn't serve any purpose. Also, reading the
file with CONFIG_LOCKDEP=y will complain:

[   63.258593] INFO: trying to register non-static key.
[   63.259113] the code is fine but needs lockdep annotation.
[   63.259596] turning off the locking correctness validator.
[   63.260073] CPU: 1 PID: 4102 Comm: perl Not tainted 4.14.0-rc8-next-20171107+ #419
[   63.260769] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014
[   63.261570] Call Trace:
[   63.261783]  dump_stack+0x5f/0x86
[   63.262062]  register_lock_class+0xe4/0x550
[   63.262408]  ? __lock_acquire+0x308/0x1170
[   63.262746]  __lock_acquire+0x7e/0x1170
[   63.263063]  lock_acquire+0x9d/0x1d0
[   63.263363]  ? sysctl_vm_numa_stat_handler+0x8f/0x2d0
[   63.263777]  ? sysctl_vm_numa_stat_handler+0x8f/0x2d0
[   63.264192]  __mutex_lock+0xb8/0x9a0
[   63.264488]  ? sysctl_vm_numa_stat_handler+0x8f/0x2d0
[   63.264942]  ? sysctl_vm_numa_stat_handler+0x8f/0x2d0
[   63.265398]  ? sysctl_vm_numa_stat_handler+0x8f/0x2d0
[   63.265840]  sysctl_vm_numa_stat_handler+0x8f/0x2d0
[   63.266270]  proc_sys_call_handler+0xe3/0x100
[   63.266655]  __vfs_read+0x33/0x1b0
[   63.266957]  vfs_read+0xa6/0x150
[   63.267244]  SyS_read+0x55/0xc0
[   63.267525]  do_syscall_64+0x56/0x140
[   63.267850]  entry_SYSCALL64_slow_path+0x25/0x25

Fixes: 920d5f77d1a25 ("mm, sysctl: make NUMA stats configurable")
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Ying Huang <ying.huang@intel.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 mm/vmstat.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/vmstat.c b/mm/vmstat.c
index e0593434fd58..40b2db6db6b1 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -72,11 +72,12 @@ static void invalid_numa_statistics(void)
 	zero_global_numa_counters();
 }
 
+static DEFINE_MUTEX(vm_numa_stat_lock);
+
 int sysctl_vm_numa_stat_handler(struct ctl_table *table, int write,
 		void __user *buffer, size_t *length, loff_t *ppos)
 {
 	int ret, oldval;
-	DEFINE_MUTEX(vm_numa_stat_lock);
 
 	mutex_lock(&vm_numa_stat_lock);
 	if (write)
-- 
2.7.4


-- 
Kees Cook
Pixel Security

             reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07 21:38 Kees Cook [this message]
2017-11-08  7:43 ` Vlastimil Babka
2017-11-08 14:20   ` Michal Hocko
2017-11-08 15:21   ` Kees Cook
2017-11-09  7:50     ` Michal Hocko
2017-11-09  1:10 ` kemi

Reply instructions:

You may reply publically 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=20171107213809.GA4314@beast \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=brouer@redhat.com \
    --cc=dave.hansen@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.com \
    --cc=vbabka@suse.cz \
    --cc=ying.huang@intel.com \
    /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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git