Message ID | 20120518222436.GD23089@lizard |
---|---|
State | New |
Headers | show |
On Fri, May 18, 2012 at 3:24 PM, Anton Vorontsov <anton.vorontsov@linaro.org> wrote: > Otherwise, unlinked file will reappear on the next boot. > > Reported-by: Kees Cook <keescook@chromium.org> > Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org> > --- > fs/pstore/ram.c | 1 + > fs/pstore/ram_core.c | 6 ++++++ > include/linux/pstore_ram.h | 1 + > 3 files changed, 8 insertions(+) > > diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c > index 3a7724b..43d9727 100644 > --- a/fs/pstore/ram.c > +++ b/fs/pstore/ram.c > @@ -186,6 +186,7 @@ static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, > return -EINVAL; > > persistent_ram_free_old(cxt->przs[id]); > + persistent_ram_zap(cxt->przs[id]); > > return 0; > } > diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c > index dff5127..28b6d7f 100644 > --- a/fs/pstore/ram_core.c > +++ b/fs/pstore/ram_core.c > @@ -336,6 +336,12 @@ void persistent_ram_free_old(struct persistent_ram_zone *prz) > prz->old_log_size = 0; > } > > +void persistent_ram_zap(struct persistent_ram_zone *prz) > +{ > + atomic_set(&prz->buffer->size, 0); There are a couple places in the ringbuffer code that assume that the data is located in the buffer in the range [0, size). It may start anywhere in that range and wrap, but address 0 in the buffer always contains data. Resetting size to 0 but leaving start non-zero may result in no data at address zero, and will cause problems in at least persistent_ram_save_old, persistent_ram_ecc_old, persistent_ram_copy_old, and the detection code in persistent_ram_post_init. These would all need to be fixed to support the dual-metadata ringbuffer option I mentioned in response to patch 3, but if you don't like that idea then just clear start here. > + persistent_ram_update_header_ecc(prz); > +} > + > static void *persistent_ram_vmap(phys_addr_t start, size_t size) > { > struct page **pages; > diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h > index 07d59b7..085199e 100644 > --- a/include/linux/pstore_ram.h > +++ b/include/linux/pstore_ram.h > @@ -69,6 +69,7 @@ struct persistent_ram_zone * __init persistent_ram_new(phys_addr_t start, > size_t size, > bool ecc); > void persistent_ram_free(struct persistent_ram_zone *prz); > +void persistent_ram_zap(struct persistent_ram_zone *prz); > struct persistent_ram_zone *persistent_ram_init_ringbuffer(struct device *dev, > bool ecc); > > -- > 1.7.9.2 >
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 3a7724b..43d9727 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -186,6 +186,7 @@ static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, return -EINVAL; persistent_ram_free_old(cxt->przs[id]); + persistent_ram_zap(cxt->przs[id]); return 0; } diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index dff5127..28b6d7f 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -336,6 +336,12 @@ void persistent_ram_free_old(struct persistent_ram_zone *prz) prz->old_log_size = 0; } +void persistent_ram_zap(struct persistent_ram_zone *prz) +{ + atomic_set(&prz->buffer->size, 0); + persistent_ram_update_header_ecc(prz); +} + static void *persistent_ram_vmap(phys_addr_t start, size_t size) { struct page **pages; diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h index 07d59b7..085199e 100644 --- a/include/linux/pstore_ram.h +++ b/include/linux/pstore_ram.h @@ -69,6 +69,7 @@ struct persistent_ram_zone * __init persistent_ram_new(phys_addr_t start, size_t size, bool ecc); void persistent_ram_free(struct persistent_ram_zone *prz); +void persistent_ram_zap(struct persistent_ram_zone *prz); struct persistent_ram_zone *persistent_ram_init_ringbuffer(struct device *dev, bool ecc);
Otherwise, unlinked file will reappear on the next boot. Reported-by: Kees Cook <keescook@chromium.org> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org> --- fs/pstore/ram.c | 1 + fs/pstore/ram_core.c | 6 ++++++ include/linux/pstore_ram.h | 1 + 3 files changed, 8 insertions(+)