From patchwork Mon Jun 13 09:45:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 9172465 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 9549360573 for ; Mon, 13 Jun 2016 09:45:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85BAB200E7 for ; Mon, 13 Jun 2016 09:45:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79528265B9; Mon, 13 Jun 2016 09:45:27 +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.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 1866D200E7 for ; Mon, 13 Jun 2016 09:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964915AbcFMJp0 (ORCPT ); Mon, 13 Jun 2016 05:45:26 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:44866 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964840AbcFMJp0 (ORCPT ); Mon, 13 Jun 2016 05:45:26 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u5D9jOiR024436 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 13 Jun 2016 09:45:24 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u5D9jNLG026419 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 13 Jun 2016 09:45:24 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u5D9jNwK019526 for ; Mon, 13 Jun 2016 09:45:23 GMT Received: from mwanda (/154.0.139.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jun 2016 02:45:22 -0700 Date: Mon, 13 Jun 2016 12:45:17 +0300 From: Dan Carpenter To: linux-sparse@vger.kernel.org Subject: [PATCH] ptrlist: use after free in last_ptr_list() Message-ID: <20160613094517.GA25301@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.0 (2016-04-01) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change is similar to 2e7dd34d11cb ('ptrlist: reading deleted items in NEXT_PTR_LIST()'). If we use DELETE_CURRENT_PTR() then we can end up with a list->nr that is zero meaning that we have to go back another list->prev to find what we want. Otherwise we dereference 0xf0f0f0f0 and crash. Signed-off-by: Dan Carpenter --- ptrlist.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ptrlist.h b/ptrlist.h index 61e159f..6f90c8f 100644 --- a/ptrlist.h +++ b/ptrlist.h @@ -78,6 +78,8 @@ static inline void *last_ptr_list(struct ptr_list *list) if (!list) return NULL; list = list->prev; + while (list->nr == 0) + list = list->prev; return PTR_ENTRY(list, list->nr-1); }