Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752872AbdBMSd4 (ORCPT ); Mon, 13 Feb 2017 13:33:56 -0500 Received: from mail-ot0-f172.google.com ([74.125.82.172]:33010 "EHLO mail-ot0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751950AbdBMSdy (ORCPT ); Mon, 13 Feb 2017 13:33:54 -0500 From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Brian Norris , Anton Vorontsov , Colin Cross , Tony Luck Subject: [PATCH 2/3] pstore: Check for prz allocation in walker Date: Mon, 13 Feb 2017 10:33:42 -0800 Message-Id: <1487010823-146018-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487010823-146018-1-git-send-email-keescook@chromium.org> References: <1487010823-146018-1-git-send-email-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of needing additional checks in callers for unallocated przs, perform the check in the walker, which gives us a more universal way to handle the situation. Signed-off-by: Kees Cook --- fs/pstore/ram.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 1d887efaaf71..11f918d34b1e 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -133,7 +133,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max, struct persistent_ram_zone *prz; int i = (*c)++; - if (i >= max) + /* Give up if we never existed or have hit the end. */ + if (!przs || i >= max) return NULL; prz = przs[i]; @@ -280,7 +281,7 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, 1, id, type, PSTORE_TYPE_PMSG, 0); /* ftrace is last since it may want to dynamically allocate memory. */ - if (!prz_ok(prz) && cxt->fprzs) { + if (!prz_ok(prz)) { if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)) { prz = ramoops_get_next_prz(cxt->fprzs, &cxt->ftrace_read_cnt, 1, id, type, -- 2.7.4