Commit 72116efd authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'pstore-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull pstore updates from Kees Cook:

 - Do not allow misconfigured ECC sizes (Sergey Shtylyov)

 - Allow for odd number of CPUs (Weichen Chen)

 - Refactor error handling to use cleanup.h

* tag 'pstore-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  pstore: inode: Use cleanup.h for struct pstore_private
  pstore: inode: Use __free(pstore_iput) for inode allocations
  pstore: inode: Convert mutex usage to guard(mutex)
  pstore: inode: Convert kfree() usage to __free(kfree)
  pstore: ram_core: fix possible overflow in persistent_ram_init_ecc()
  pstore/ram: Fix crash when setting number of cpus to an odd number
parents 4d925f60 24a0b5e1
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/pstore.h> #include <linux/pstore.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/cleanup.h>
#include "internal.h" #include "internal.h"
...@@ -34,6 +35,8 @@ static LIST_HEAD(records_list); ...@@ -34,6 +35,8 @@ static LIST_HEAD(records_list);
static DEFINE_MUTEX(pstore_sb_lock); static DEFINE_MUTEX(pstore_sb_lock);
static struct super_block *pstore_sb; static struct super_block *pstore_sb;
DEFINE_FREE(pstore_iput, struct inode *, if (_T) iput(_T))
struct pstore_private { struct pstore_private {
struct list_head list; struct list_head list;
struct dentry *dentry; struct dentry *dentry;
...@@ -60,11 +63,12 @@ static void free_pstore_private(struct pstore_private *private) ...@@ -60,11 +63,12 @@ static void free_pstore_private(struct pstore_private *private)
} }
kfree(private); kfree(private);
} }
DEFINE_FREE(pstore_private, struct pstore_private *, free_pstore_private(_T));
static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos) static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos)
{ {
struct pstore_private *ps = s->private; struct pstore_private *ps = s->private;
struct pstore_ftrace_seq_data *data; struct pstore_ftrace_seq_data *data __free(kfree) = NULL;
data = kzalloc(sizeof(*data), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
...@@ -72,13 +76,10 @@ static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos) ...@@ -72,13 +76,10 @@ static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos)
data->off = ps->total_size % REC_SIZE; data->off = ps->total_size % REC_SIZE;
data->off += *pos * REC_SIZE; data->off += *pos * REC_SIZE;
if (data->off + REC_SIZE > ps->total_size) { if (data->off + REC_SIZE > ps->total_size)
kfree(data);
return NULL; return NULL;
}
return data;
return_ptr(data);
} }
static void pstore_ftrace_seq_stop(struct seq_file *s, void *v) static void pstore_ftrace_seq_stop(struct seq_file *s, void *v)
...@@ -182,25 +183,21 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry) ...@@ -182,25 +183,21 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
{ {
struct pstore_private *p = d_inode(dentry)->i_private; struct pstore_private *p = d_inode(dentry)->i_private;
struct pstore_record *record = p->record; struct pstore_record *record = p->record;
int rc = 0;
if (!record->psi->erase) if (!record->psi->erase)
return -EPERM; return -EPERM;
/* Make sure we can't race while removing this file. */ /* Make sure we can't race while removing this file. */
mutex_lock(&records_list_lock); scoped_guard(mutex, &records_list_lock) {
if (!list_empty(&p->list)) if (!list_empty(&p->list))
list_del_init(&p->list); list_del_init(&p->list);
else else
rc = -ENOENT; return -ENOENT;
p->dentry = NULL; p->dentry = NULL;
mutex_unlock(&records_list_lock); }
if (rc)
return rc; scoped_guard(mutex, &record->psi->read_mutex)
record->psi->erase(record);
mutex_lock(&record->psi->read_mutex);
record->psi->erase(record);
mutex_unlock(&record->psi->read_mutex);
return simple_unlink(dir, dentry); return simple_unlink(dir, dentry);
} }
...@@ -292,19 +289,16 @@ static struct dentry *psinfo_lock_root(void) ...@@ -292,19 +289,16 @@ static struct dentry *psinfo_lock_root(void)
{ {
struct dentry *root; struct dentry *root;
mutex_lock(&pstore_sb_lock); guard(mutex)(&pstore_sb_lock);
/* /*
* Having no backend is fine -- no records appear. * Having no backend is fine -- no records appear.
* Not being mounted is fine -- nothing to do. * Not being mounted is fine -- nothing to do.
*/ */
if (!psinfo || !pstore_sb) { if (!psinfo || !pstore_sb)
mutex_unlock(&pstore_sb_lock);
return NULL; return NULL;
}
root = pstore_sb->s_root; root = pstore_sb->s_root;
inode_lock(d_inode(root)); inode_lock(d_inode(root));
mutex_unlock(&pstore_sb_lock);
return root; return root;
} }
...@@ -319,19 +313,19 @@ int pstore_put_backend_records(struct pstore_info *psi) ...@@ -319,19 +313,19 @@ int pstore_put_backend_records(struct pstore_info *psi)
if (!root) if (!root)
return 0; return 0;
mutex_lock(&records_list_lock); scoped_guard(mutex, &records_list_lock) {
list_for_each_entry_safe(pos, tmp, &records_list, list) { list_for_each_entry_safe(pos, tmp, &records_list, list) {
if (pos->record->psi == psi) { if (pos->record->psi == psi) {
list_del_init(&pos->list); list_del_init(&pos->list);
rc = simple_unlink(d_inode(root), pos->dentry); rc = simple_unlink(d_inode(root), pos->dentry);
if (WARN_ON(rc)) if (WARN_ON(rc))
break; break;
d_drop(pos->dentry); d_drop(pos->dentry);
dput(pos->dentry); dput(pos->dentry);
pos->dentry = NULL; pos->dentry = NULL;
}
} }
} }
mutex_unlock(&records_list_lock);
inode_unlock(d_inode(root)); inode_unlock(d_inode(root));
...@@ -346,29 +340,27 @@ int pstore_put_backend_records(struct pstore_info *psi) ...@@ -346,29 +340,27 @@ int pstore_put_backend_records(struct pstore_info *psi)
int pstore_mkfile(struct dentry *root, struct pstore_record *record) int pstore_mkfile(struct dentry *root, struct pstore_record *record)
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode __free(pstore_iput) = NULL;
int rc = 0;
char name[PSTORE_NAMELEN]; char name[PSTORE_NAMELEN];
struct pstore_private *private, *pos; struct pstore_private *private __free(pstore_private) = NULL, *pos;
size_t size = record->size + record->ecc_notice_size; size_t size = record->size + record->ecc_notice_size;
if (WARN_ON(!inode_is_locked(d_inode(root)))) if (WARN_ON(!inode_is_locked(d_inode(root))))
return -EINVAL; return -EINVAL;
rc = -EEXIST; guard(mutex)(&records_list_lock);
/* Skip records that are already present in the filesystem. */ /* Skip records that are already present in the filesystem. */
mutex_lock(&records_list_lock);
list_for_each_entry(pos, &records_list, list) { list_for_each_entry(pos, &records_list, list) {
if (pos->record->type == record->type && if (pos->record->type == record->type &&
pos->record->id == record->id && pos->record->id == record->id &&
pos->record->psi == record->psi) pos->record->psi == record->psi)
goto fail; return -EEXIST;
} }
rc = -ENOMEM;
inode = pstore_get_inode(root->d_sb); inode = pstore_get_inode(root->d_sb);
if (!inode) if (!inode)
goto fail; return -ENOMEM;
inode->i_mode = S_IFREG | 0444; inode->i_mode = S_IFREG | 0444;
inode->i_fop = &pstore_file_operations; inode->i_fop = &pstore_file_operations;
scnprintf(name, sizeof(name), "%s-%s-%llu%s", scnprintf(name, sizeof(name), "%s-%s-%llu%s",
...@@ -378,11 +370,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) ...@@ -378,11 +370,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
private = kzalloc(sizeof(*private), GFP_KERNEL); private = kzalloc(sizeof(*private), GFP_KERNEL);
if (!private) if (!private)
goto fail_inode; return -ENOMEM;
dentry = d_alloc_name(root, name); dentry = d_alloc_name(root, name);
if (!dentry) if (!dentry)
goto fail_private; return -ENOMEM;
private->dentry = dentry; private->dentry = dentry;
private->record = record; private->record = record;
...@@ -393,20 +385,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) ...@@ -393,20 +385,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
inode_set_mtime_to_ts(inode, inode_set_mtime_to_ts(inode,
inode_set_ctime_to_ts(inode, record->time)); inode_set_ctime_to_ts(inode, record->time));
d_add(dentry, inode); d_add(dentry, no_free_ptr(inode));
list_add(&private->list, &records_list); list_add(&(no_free_ptr(private))->list, &records_list);
mutex_unlock(&records_list_lock);
return 0; return 0;
fail_private:
free_pstore_private(private);
fail_inode:
iput(inode);
fail:
mutex_unlock(&records_list_lock);
return rc;
} }
/* /*
...@@ -451,9 +434,8 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent) ...@@ -451,9 +434,8 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent)
if (!sb->s_root) if (!sb->s_root)
return -ENOMEM; return -ENOMEM;
mutex_lock(&pstore_sb_lock); scoped_guard(mutex, &pstore_sb_lock)
pstore_sb = sb; pstore_sb = sb;
mutex_unlock(&pstore_sb_lock);
pstore_get_records(0); pstore_get_records(0);
...@@ -468,17 +450,14 @@ static struct dentry *pstore_mount(struct file_system_type *fs_type, ...@@ -468,17 +450,14 @@ static struct dentry *pstore_mount(struct file_system_type *fs_type,
static void pstore_kill_sb(struct super_block *sb) static void pstore_kill_sb(struct super_block *sb)
{ {
mutex_lock(&pstore_sb_lock); guard(mutex)(&pstore_sb_lock);
WARN_ON(pstore_sb && pstore_sb != sb); WARN_ON(pstore_sb && pstore_sb != sb);
kill_litter_super(sb); kill_litter_super(sb);
pstore_sb = NULL; pstore_sb = NULL;
mutex_lock(&records_list_lock); guard(mutex)(&records_list_lock);
INIT_LIST_HEAD(&records_list); INIT_LIST_HEAD(&records_list);
mutex_unlock(&records_list_lock);
mutex_unlock(&pstore_sb_lock);
} }
static struct file_system_type pstore_fs_type = { static struct file_system_type pstore_fs_type = {
......
...@@ -529,6 +529,7 @@ static int ramoops_init_przs(const char *name, ...@@ -529,6 +529,7 @@ static int ramoops_init_przs(const char *name,
} }
zone_sz = mem_sz / *cnt; zone_sz = mem_sz / *cnt;
zone_sz = ALIGN_DOWN(zone_sz, 2);
if (!zone_sz) { if (!zone_sz) {
dev_err(dev, "%s zone size == 0\n", name); dev_err(dev, "%s zone size == 0\n", name);
goto fail; goto fail;
......
...@@ -190,7 +190,7 @@ static int persistent_ram_init_ecc(struct persistent_ram_zone *prz, ...@@ -190,7 +190,7 @@ static int persistent_ram_init_ecc(struct persistent_ram_zone *prz,
{ {
int numerr; int numerr;
struct persistent_ram_buffer *buffer = prz->buffer; struct persistent_ram_buffer *buffer = prz->buffer;
int ecc_blocks; size_t ecc_blocks;
size_t ecc_total; size_t ecc_total;
if (!ecc_info || !ecc_info->ecc_size) if (!ecc_info || !ecc_info->ecc_size)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment