From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51C59C4CECE for ; Thu, 12 Mar 2020 11:30:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2418A20716 for ; Thu, 12 Mar 2020 11:30:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Z8yMzEEr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726912AbgCLLaq (ORCPT ); Thu, 12 Mar 2020 07:30:46 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:40902 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgCLLap (ORCPT ); Thu, 12 Mar 2020 07:30:45 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02CBRjb1108728; Thu, 12 Mar 2020 11:30:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2020-01-29; bh=6cxapv6i42P6PP1hBm0F3eTaX8qg+2ZGM/MqdG0Jkf8=; b=Z8yMzEErDaa5mAbYdHfycg26zLYu9HwCVey1x8hYlIygVzzaoqEQUmL5fqJ0V2Mga6La xKyDTgaI8PxxL29mMrS8B8REXqfYomb+AsRHbuf9I/CqxdXOsdfoQUgmK0nWvkjAN+Ze bEQJBcvPrsCFvyO9PuCAgAXWQLhFYRMvN32XqdX9z0le6d8VwPahdM1rpvd/aWSoupfO xOES3U88Ukc3u9496fGoVTL2zmKb3bia/S492hSXI+wM6YYUBmF5wZrOgpFO90cAMTOR EwF2Iqkf0BIBWO5bRH7Mqd0QU+r2zGnbaw5Bwa77e+gyzI04657Lmvn9A1ekPx6cmn90 cg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2yqkg886yu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Mar 2020 11:30:16 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02CBMVJ6008412; Thu, 12 Mar 2020 11:30:15 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2yqkvmh1vw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Mar 2020 11:30:15 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 02CBUDTq001467; Thu, 12 Mar 2020 11:30:13 GMT Received: from mwanda (/41.57.98.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 12 Mar 2020 04:30:13 -0700 Date: Thu, 12 Mar 2020 14:30:06 +0300 From: Dan Carpenter To: Alexander Potapenko Cc: Thomas Gleixner , Andrew Morton , Josh Poimboeuf , Stephen Rothwell , Miles Chen , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] lib/stackdepot.c: fix a condition in stack_depot_fetch() Message-ID: <20200312113006.GA20562@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: Mutt/1.10.1 (2018-07-13) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9557 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003120062 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9557 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1011 lowpriorityscore=0 mlxlogscore=999 spamscore=0 phishscore=0 adultscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003120062 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We should check for a NULL pointer first before adding the offset. Otherwise if the pointer is NULL and the offset is non-zero, it will lead to an Oops. Fixes: d45048e65a59 ("lib/stackdepot.c: check depot_index before accessing the stack slab") Signed-off-by: Dan Carpenter --- lib/stackdepot.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index da5d1880bf34..2caffc64e4c8 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -207,18 +207,16 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, size_t offset = parts.offset << STACK_ALLOC_ALIGN; struct stack_record *stack; + *entries = NULL; if (parts.slabindex > depot_index) { WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n", parts.slabindex, depot_index, handle); - *entries = NULL; return 0; } slab = stack_slabs[parts.slabindex]; - stack = slab + offset; - if (!stack) { - *entries = NULL; + if (!slab) return 0; - } + stack = slab + offset; *entries = stack->entries; return stack->size; -- 2.20.1