From patchwork Fri Nov 22 11:25:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11257861 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1343514DB for ; Fri, 22 Nov 2019 11:26:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D2BAB2070E for ; Fri, 22 Nov 2019 11:26:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aZvN6B/Q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D2BAB2070E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 690C26B04C1; Fri, 22 Nov 2019 06:26:31 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 61CB06B04C2; Fri, 22 Nov 2019 06:26:31 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E2C06B04C3; Fri, 22 Nov 2019 06:26:31 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 35D206B04C1 for ; Fri, 22 Nov 2019 06:26:31 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id EEE10180AD830 for ; Fri, 22 Nov 2019 11:26:30 +0000 (UTC) X-FDA: 76183685340.10.light28_9024a15106b62 X-Spam-Summary: 2,0,0,a485c3f1fa64d5dd,d41d8cd98f00b204,35mxxxqykcmmpurmn0pxxpun.lxvurw36-vvt4jlt.x0p@flex--glider.bounces.google.com,:vegard.nossum@oracle.com:dvyukov@google.com::glider@google.com:viro@zeniv.linux.org.uk:adilger.kernel@dilger.ca:akpm@linux-foundation.org:andreyknvl@google.com:aryabinin@virtuozzo.com:luto@kernel.org:ard.biesheuvel@linaro.org:arnd@arndb.de:hch@infradead.org:hch@lst.de:darrick.wong@oracle.com:davem@davemloft.net:dmitry.torokhov@gmail.com:ebiggers@google.com:edumazet@google.com:ericvh@gmail.com:gregkh@linuxfoundation.org:harry.wentland@amd.com:herbert@gondor.apana.org.au:iii@linux.ibm.com:mingo@elte.hu:jasowang@redhat.com:axboe@kernel.dk:m.szyprowski@samsung.com:elver@google.com:mark.rutland@arm.com:martin.petersen@oracle.com:schwidefsky@de.ibm.com:willy@infradead.org:mst@redhat.com:monstr@monstr.eu:pmladek@suse.com:cai@lca.pw:rdunlap@infradead.org:robin.murphy@arm.com:sergey.senozhatsky@gmail.com:rostedt@goodmis.org:tiwai@suse.com:tytso@mit.edu :tglx@li X-HE-Tag: light28_9024a15106b62 X-Filterd-Recvd-Size: 4878 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Nov 2019 11:26:30 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id z10so3758426wrr.5 for ; Fri, 22 Nov 2019 03:26:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=r731EqFOOipqjSJIJz8yFC14GnHhtvfLOt7Qdhze454=; b=aZvN6B/QnOjGbZNn9Xfc6FqUAlrY39i5UK2Ts6Qv7ZBNbtBYCeMsC7Z3CF7AE71jLA 7fNUbpfnZ4SoVFerfELeylEpfknfB2i0bSxF6QiB3VLjO26XxjO+62WjuIE/lj2RLEZA buMdD3nGdQ/NjCdHdbGf8p9L+cN4kCCPfUv0K+d3F5DajRlQTNwQVRQPZjhhDfX8t0OE 6Wymjed/0RLiY8AJCK5hAcN0nmeOfthgU2V7dAMC5Q3iGBC1uzZb7X9uhyr17KATu6mI EKbivcQH1XW/qLfos2pjUXhXxWzkKuAUvn8gkFT5s2DLLgKAyq07Bxzg12BSd9vMnmN1 gDiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=r731EqFOOipqjSJIJz8yFC14GnHhtvfLOt7Qdhze454=; b=ooj869oXD0D4NCT5gPZYKybmJpRgbTLLc0CYyBvMI0aquwXuyFGzRBrmVlDhJ0NE3u M3xj4+owaYeE25bIV0GOHDcZ/X7H9fok4Qh8PcP5b9d5JV7pRGASQ187G0pId++Ptzy8 kY/d2J6oYNpoToVD3jFzb8G232JZ2zyOec9dxqncRvdrTF19rhZO/CZULWZDEdWQrdgk cMvwvAclPgyh24nMiiDPMlp2ec4NKB1kKCMvW/QHSsPytsduQMKR41TVeCJ1jDkm+6R9 W+Gm6tXTeSZKp7tF+jOez2YuucfdNsniu3HQC2i1t+ig064uqzCwKTUO731eFDIJJwnB iBlg== X-Gm-Message-State: APjAAAXepNuRjY3bKXXmCGMSkat3z3do5hHwMSzhaEVvqSv13Yj5zk2I 0b3Z5QV+FLC9gs4xKrELcROR6tVmE3M= X-Google-Smtp-Source: APXvYqx1HQXLnbiR1h40cNxv1i6SXfSe9OAb83ZkjJAEEsHucL3i7WGLPob6pAlfVDOFLHahFd77+uyWTr0= X-Received: by 2002:adf:aa92:: with SMTP id h18mr17800677wrc.150.1574421988971; Fri, 22 Nov 2019 03:26:28 -0800 (PST) Date: Fri, 22 Nov 2019 12:25:46 +0100 In-Reply-To: <20191122112621.204798-1-glider@google.com> Message-Id: <20191122112621.204798-2-glider@google.com> Mime-Version: 1.0 References: <20191122112621.204798-1-glider@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog Subject: [PATCH RFC v3 01/36] stackdepot: check depot_index before accessing the stack slab From: glider@google.com To: Vegard Nossum , Dmitry Vyukov , linux-mm@kvack.org Cc: glider@google.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, akpm@linux-foundation.org, andreyknvl@google.com, aryabinin@virtuozzo.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@infradead.org, hch@lst.de, darrick.wong@oracle.com, davem@davemloft.net, dmitry.torokhov@gmail.com, ebiggers@google.com, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, iii@linux.ibm.com, mingo@elte.hu, jasowang@redhat.com, axboe@kernel.dk, m.szyprowski@samsung.com, elver@google.com, mark.rutland@arm.com, martin.petersen@oracle.com, schwidefsky@de.ibm.com, willy@infradead.org, mst@redhat.com, monstr@monstr.eu, pmladek@suse.com, cai@lca.pw, rdunlap@infradead.org, robin.murphy@arm.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, gor@linux.ibm.com, wsa@the-dreams.de X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Avoid crashes on corrupted stack ids. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: linux-mm@kvack.org --- v3: - fix the return statement Change-Id: I0a0b38ed5057090696a2c6ff0be7cfcc24ae6738 --- lib/stackdepot.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index ed717dd08ff3..0bc6182bc7a6 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -198,9 +198,22 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries) { union handle_parts parts = { .handle = handle }; - void *slab = stack_slabs[parts.slabindex]; + void *slab; size_t offset = parts.offset << STACK_ALLOC_ALIGN; - struct stack_record *stack = slab + offset; + struct stack_record *stack; + + 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; + return 0; + } *entries = stack->entries; return stack->size;