From patchwork Mon Mar 6 21:55:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9607763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AFC8A601D2 for ; Mon, 6 Mar 2017 22:24:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00FED28482 for ; Mon, 6 Mar 2017 22:24:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7B1F28485; Mon, 6 Mar 2017 22:24:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6213528482 for ; Mon, 6 Mar 2017 22:24:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932186AbdCFWYz (ORCPT ); Mon, 6 Mar 2017 17:24:55 -0500 Received: from mail-pf0-f179.google.com ([209.85.192.179]:36855 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753444AbdCFWYo (ORCPT ); Mon, 6 Mar 2017 17:24:44 -0500 Received: by mail-pf0-f179.google.com with SMTP id o126so18602972pfb.3 for ; Mon, 06 Mar 2017 14:23:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Sr7Jp2ItHgjy/etCnbohq21o071ZhCDX7otjysOImN0=; b=i5YaRXUn9fFVj6t73uHFVD7yBoBJbelxJC6hH2O8HbzhMXwM8qZ/Qy0ddEaSE54LiF 2ABmN1aammFsDvGMA55B9/WYBxaUyrLa7qs+Lm75oVVvyQPa3N/rhnC37QDo7oNMe3sY LhHGvdilyLOM66nPcEXmbuq5Gl8pvZzKg7J2A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Sr7Jp2ItHgjy/etCnbohq21o071ZhCDX7otjysOImN0=; b=EwTBSV3FO4/INRl4dwIQ810mELZ8KO8TW6RSSj7LC4BpsQ74+886+rGLwiCef+RBzc OHofyZdQZQ4rLeC/T8oWqhL9jnxjZtNxu+3vQGh8dL3fQh00Xs0nrY3Z8tJ+tZmcfKi0 W3sxjXKnrvnDUG6mavP3mxLpLk8Q4Dymvy53wJu8uSKflB8nTcmivOxdhOjH2il7ylRL rp+oO/QJBfiFRKhL23J2Cysh6S9j3H0XT/qfsUNwDGr7gCBibLU29UAr0tJbCRdJFUY+ 1b+RGslocJUb3TVovttdkipCahrZNbz1RxnKYvIk++QJrWSzMg18nGWRtMaCLyp5+exk 1ltQ== X-Gm-Message-State: AMke39m4xFMSvbYXNeemd1siAz1sSVCH9GBl2Wq+C51UYWWxGZrDx8h2Zka+r5x+WiDB5V76 X-Received: by 10.99.116.70 with SMTP id e6mr22910964pgn.135.1488837342391; Mon, 06 Mar 2017 13:55:42 -0800 (PST) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id d3sm41415532pfc.51.2017.03.06.13.55.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 13:55:41 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Nobuhiro Iwamatsu , Qiuxu Zhuo , Ard Biesheuvel , Anton Vorontsov , Colin Cross , Tony Luck , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "Rafael J. Wysocki" , Len Brown , Matt Fleming , Nathan Fontenot , Pan Xinhui , Daniel Axtens , Paul Gortmaker , Geliang Tang , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, linux-efi@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 14/18] pstore: Do not duplicate record metadata Date: Mon, 6 Mar 2017 13:55:28 -0800 Message-Id: <1488837332-71582-15-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488837332-71582-1-git-send-email-keescook@chromium.org> References: <1488837332-71582-1-git-send-email-keescook@chromium.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This switches the inode-private data from carrying duplicate metadata to keeping the record passed in during pstore_mkfile(). Signed-off-by: Kees Cook --- fs/pstore/inode.c | 57 ++++++++++++++++++++++++++-------------------------- fs/pstore/platform.c | 6 ++---- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 3d1f047e4f41..0ea281b457fa 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -47,12 +47,8 @@ static LIST_HEAD(allpstore); struct pstore_private { struct list_head list; - struct pstore_info *psi; - enum pstore_type_id type; - u64 id; - int count; - ssize_t size; - char *buf; + struct pstore_record *record; + size_t total_size; }; struct pstore_ftrace_seq_data { @@ -67,7 +63,10 @@ static void free_pstore_private(struct pstore_private *private) { if (!private) return; - kfree(private->buf); + if (private->record) { + kfree(private->record->buf); + kfree(private->record); + } kfree(private); } @@ -80,9 +79,9 @@ static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos) if (!data) return NULL; - data->off = ps->size % REC_SIZE; + data->off = ps->total_size % REC_SIZE; data->off += *pos * REC_SIZE; - if (data->off + REC_SIZE > ps->size) { + if (data->off + REC_SIZE > ps->total_size) { kfree(data); return NULL; } @@ -102,7 +101,7 @@ static void *pstore_ftrace_seq_next(struct seq_file *s, void *v, loff_t *pos) struct pstore_ftrace_seq_data *data = v; data->off += REC_SIZE; - if (data->off + REC_SIZE > ps->size) + if (data->off + REC_SIZE > ps->total_size) return NULL; (*pos)++; @@ -113,7 +112,9 @@ static int pstore_ftrace_seq_show(struct seq_file *s, void *v) { struct pstore_private *ps = s->private; struct pstore_ftrace_seq_data *data = v; - struct pstore_ftrace_record *rec = (void *)(ps->buf + data->off); + struct pstore_ftrace_record *rec; + + rec = (struct pstore_ftrace_record *)(ps->record->buf + data->off); seq_printf(s, "CPU:%d ts:%llu %08lx %08lx %pf <- %pF\n", pstore_ftrace_decode_cpu(rec), @@ -133,7 +134,7 @@ static const struct seq_operations pstore_ftrace_seq_ops = { static int pstore_check_syslog_permissions(struct pstore_private *ps) { - switch (ps->type) { + switch (ps->record->type) { case PSTORE_TYPE_DMESG: case PSTORE_TYPE_CONSOLE: return check_syslog_permissions(SYSLOG_ACTION_READ_ALL, @@ -149,9 +150,10 @@ static ssize_t pstore_file_read(struct file *file, char __user *userbuf, struct seq_file *sf = file->private_data; struct pstore_private *ps = sf->private; - if (ps->type == PSTORE_TYPE_FTRACE) + if (ps->record->type == PSTORE_TYPE_FTRACE) return seq_read(file, userbuf, count, ppos); - return simple_read_from_buffer(userbuf, count, ppos, ps->buf, ps->size); + return simple_read_from_buffer(userbuf, count, ppos, + ps->record->buf, ps->total_size); } static int pstore_file_open(struct inode *inode, struct file *file) @@ -165,7 +167,7 @@ static int pstore_file_open(struct inode *inode, struct file *file) if (err) return err; - if (ps->type == PSTORE_TYPE_FTRACE) + if (ps->record->type == PSTORE_TYPE_FTRACE) sops = &pstore_ftrace_seq_ops; err = seq_open(file, sops); @@ -201,17 +203,18 @@ static const struct file_operations pstore_file_operations = { static int pstore_unlink(struct inode *dir, struct dentry *dentry) { struct pstore_private *p = d_inode(dentry)->i_private; + struct pstore_record *record = p->record; int err; err = pstore_check_syslog_permissions(p); if (err) return err; - if (p->psi->erase) { - mutex_lock(&p->psi->read_mutex); - p->psi->erase(p->type, p->id, p->count, - d_inode(dentry)->i_ctime, p->psi); - mutex_unlock(&p->psi->read_mutex); + if (record->psi->erase) { + mutex_lock(&record->psi->read_mutex); + record->psi->erase(record->type, record->id, record->count, + d_inode(dentry)->i_ctime, record->psi); + mutex_unlock(&record->psi->read_mutex); } else { return -EPERM; } @@ -323,9 +326,9 @@ int pstore_mkfile(struct pstore_record *record) spin_lock_irqsave(&allpstore_lock, flags); list_for_each_entry(pos, &allpstore, list) { - if (pos->type == record->type && - pos->id == record->id && - pos->psi == record->psi) { + if (pos->record->type == record->type && + pos->record->id == record->id && + pos->record->psi == record->psi) { rc = -EEXIST; break; } @@ -343,10 +346,7 @@ int pstore_mkfile(struct pstore_record *record) private = kzalloc(sizeof(*private), GFP_KERNEL); if (!private) goto fail_alloc; - private->type = record->type; - private->id = record->id; - private->count = record->count; - private->psi = record->psi; + private->record = record; switch (record->type) { case PSTORE_TYPE_DMESG: @@ -402,8 +402,7 @@ int pstore_mkfile(struct pstore_record *record) if (!dentry) goto fail_lockedalloc; - private->buf = record->buf; - inode->i_size = private->size = size; + inode->i_size = private->total_size = size; inode->i_private = private; diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 072326625629..aa3d6e572ede 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -852,14 +852,12 @@ void pstore_get_records(int quiet) decompress_record(record); rc = pstore_mkfile(record); if (rc) { - /* pstore_mkfile() did not take buf, so free it. */ + /* pstore_mkfile() did not take record, so free it. */ kfree(record->buf); + kfree(record); if (rc != -EEXIST || !quiet) failed++; } - - /* Reset for next record. */ - kfree(record); } if (psi->close) psi->close(psi);