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: 735963 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vcZ3B2FJYz9sN5 for ; Tue, 7 Mar 2017 09:19:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="i5YaRXUn"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vcZ3B0yTTzDqhN for ; Tue, 7 Mar 2017 09:19:50 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="i5YaRXUn"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pg0-x233.google.com (mail-pg0-x233.google.com [IPv6:2607:f8b0:400e:c05::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vcYWN0XJXzDqXt for ; Tue, 7 Mar 2017 08:55:44 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="i5YaRXUn"; dkim-atps=neutral Received: by mail-pg0-x233.google.com with SMTP id 77so26495073pgc.1 for ; Mon, 06 Mar 2017 13:55:43 -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=YFLJTMuufq0jBTE6KwkEZwvPgtD+9SuyzdAHxrFPAGvSUslHjhgRZ8bj5vqZJ4zumo G7tNoLQOPNb53P5/rcV7CCsjdGHOdlJXp5Iqfe209EQl6lt/627DDquGLrR6qXrxjhcH upr9EhOtwQDR+3UYuuNc286pgkEz8JdJWNMVa/AIU2lEXJ85dR0Ty+uAOTlmjEGMa3Rh dNCsfo28mDIabX/FMJgLHbhvG+WLtmW7zUCIyTcNbWSdpEg1hmkcMyfhRe619uLbMfUE KD2upCY5447OjoupaKuu/qegSJqcAHNq41zMP2XJ21EeR9z//V8J1rYZbcS06g8HPx3K A+IA== X-Gm-Message-State: AMke39nGbRkckp5PJ401hDbHvSSrO/Y7jSOPJP1hIaHqvb1PeaTT4QYb87Ljoa1kWznSaVPS 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 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> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, linux-doc@vger.kernel.org, Matt Fleming , Pan Xinhui , Paul Gortmaker , Paul Mackerras , Anton Vorontsov , linux-acpi@vger.kernel.org, Nathan Fontenot , Len Brown , Kees Cook , Nobuhiro Iwamatsu , Geliang Tang , Tony Luck , Daniel Axtens , Qiuxu Zhuo , Ard Biesheuvel , "Rafael J. Wysocki" , Colin Cross , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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);