Skip to contentSkip to conversation

pstore: gracefully handle NULL pstore_info functions

PATCH Superseded Kees Cook 2 participants 3 messages Nov 17, 2011 Pstore filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 pstore: gracefully handle NULL pstore_info functions

If a pstore backend doesn't want to support various portions of the pstore interface, it can just leave those functions NULL instead of creating no-op stubs.

---
 fs/pstore/inode.c    |    3 ++-
 fs/pstore/platform.c |   11 ++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
fs/pstore/inode.c +2 -1
index 379a02d..b3b426e 100644
@@ -80,7 +80,8 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
 {
 	struct pstore_private *p = dentry->d_inode->i_private;
 
-	p->psi->erase(p->type, p->id, p->psi);
+	if (p->psi->erase)
+		p->psi->erase(p->type, p->id, p->psi);
 
 	return simple_unlink(dir, dentry);
 }
fs/pstore/platform.c +6 -5
index f146d89..e12dfd7 100644
@@ -178,7 +178,8 @@ int pstore_register(struct pstore_info *psi)
 	if (pstore_is_mounted())
 		pstore_get_records(0);
 
-	kmsg_dump_register(&pstore_dumper);
+	if (psi->write && psi->buf && psi->bufsize)
+		kmsg_dump_register(&pstore_dumper);
 
 	pstore_timer.expires = jiffies + PSTORE_INTERVAL;
 	add_timer(&pstore_timer);
@@ -203,12 +204,11 @@ void pstore_get_records(int quiet)
 	struct timespec		time;
 	int			failed = 0, rc;
 
-	if (!psi)
+	if (!psi || !psi->read)
 		return;
 
 	mutex_lock(&psi->read_mutex);
-	rc = psi->open(psi);
-	if (rc)
+	if (psi->open && psi->open(psi))
 		goto out;
 
 	while ((size = psi->read(&id, &type, &time, &buf, psi)) > 0) {
@@ -219,7 +219,8 @@ void pstore_get_records(int quiet)
 		if (rc && (rc != -EEXIST || !quiet))
 			failed++;
 	}
-	psi->close(psi);
+	if (psi->close)
+		psi->close(psi);
 out:
 	mutex_unlock(&psi->read_mutex);
 
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 3 lines · Kees Cook

-       kmsg_dump_register(&pstore_dumper);
+       if (psi->write && psi->buf && psi->bufsize)
+               kmsg_dump_register(&pstore_dumper);

I can see that you might not need the other parts of the pstore interface if your back-end is very simple (e.g. only has space for a single record). But stub functions are cheap - so it isn't clear who should pay the overhead.

BUT - without psi->write!? What use is it!? I think in an early version I refused the registration with -EINVAL - but akpm convinced me it was a waste of electrons:

Quoted 7 lines · On Wed, 1 Dec 2010 16:51:39 Andrew Morton <[email protected]> wrote:

Review

Quoted 3 lines
(quoted diff) +3 -0
+     if (!psi->reader || !psi->writer || !psi->eraser) {
+             spin_unlock(&pstore_lock);
+             return -EINVAL;

It doesn't seem appropriate to check this here. It's a programming error! Just install the thing and let the kernel oops - the programmer will notice.

Hiding the lack of a ->write function by quietly accepting the registration, but not hooking into kmsg_dump doesn't sound useful in any scenario.

-Tony

Dang - pstore is coming up on a year old - time flies when you're having fun.

author
#2 lore raw
Quoted 9 lines · Tony Luck
Quoted 3 lines · Kees Cook

-       kmsg_dump_register(&pstore_dumper);
+       if (psi->write && psi->buf && psi->bufsize)
+               kmsg_dump_register(&pstore_dumper);

I can see that you might not need the other parts of the pstore interface if your back-end is very simple (e.g. only has space for a single record). But stub functions are cheap - so it isn't clear who should pay the overhead.

Okay, fine by me. :) I'll resend with just the open/read/close/erase checked.

-Kees

Signature · 2 lines
Kees Cook
ChromeOS Security