From patchwork Wed Oct 30 14:22:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11219607 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 A771E1668 for ; Wed, 30 Oct 2019 14:22:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 73FA12087E for ; Wed, 30 Oct 2019 14:22:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tuSSH/RX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73FA12087E 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 3E3E26B0006; Wed, 30 Oct 2019 10:22:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 397656B000A; Wed, 30 Oct 2019 10:22:48 -0400 (EDT) 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 25AB76B000C; Wed, 30 Oct 2019 10:22:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 028DE6B0006 for ; Wed, 30 Oct 2019 10:22:47 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id A6E261F10 for ; Wed, 30 Oct 2019 14:22:47 +0000 (UTC) X-FDA: 76100667174.26.roll29_356b1125ab15f X-Spam-Summary: 2,0,0,50d9235414b14d03,d41d8cd98f00b204,3tzy5xqykcmguzwrs5u22uzs.q20zw18b-00y9oqy.25u@flex--glider.bounces.google.com,:vegard.nossum@oracle.com:dvyukov@google.com::viro@zeniv.linux.org.uk:akpm@linux-foundation.org:aryabinin@virtuozzo.com:luto@kernel.org:ard.biesheuvel@linaro.org:arnd@arndb.de:hch@lst.de:dmitry.torokhov@gmail.com:edumazet@google.com:ericvh@gmail.com:gregkh@linuxfoundation.org:harry.wentland@amd.com:herbert@gondor.apana.org.au:mingo@elte.hu:axboe@kernel.dk:martin.petersen@oracle.com:schwidefsky@de.ibm.com:mst@redhat.com:monstr@monstr.eu:pmladek@suse.com:sergey.senozhatsky@gmail.com:rostedt@goodmis.org:tiwai@suse.com:tytso@mit.edu:tglx@linutronix.de:wsa@the-dreams.de:gor@linux.ibm.com:iii@linux.ibm.com:mark.rutland@arm.com:willy@infradead.org:rdunlap@infradead.org:andreyknvl@google.com:elver@google.com:glider@google.com,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747 :1777:17 X-HE-Tag: roll29_356b1125ab15f X-Filterd-Recvd-Size: 4694 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Oct 2019 14:22:46 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id s9so1386678wrw.23 for ; Wed, 30 Oct 2019 07:22:46 -0700 (PDT) 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=wepTYO8w6YbsFcNGVBbCvFTC7ov3ermwyIo9NfCllcM=; b=tuSSH/RXaOYvoaCX05Hm4ebL/1iuObTQEqwJVyYhTco2kzaPuGDZQJi5zHsS5aJRbW 7AqUYnjppQRVWp+rg4utFpxSSqVXDMy5FWmqFti3G5cBo15GdUHpoLkWu25xVOIMdhEM tQbG5unhrg+jLDMxQya0Yv0SY83bYZ0LOfRkepC0ldUl0OqeTWHf3iU7uufqhxemi6he y45n8QmE72CKBqHplqqY2qR/ye6uPq85OaYOIXV24yZhP0WJJ7YUzO/NW7XcnCc6B88s 9lRADRPxbf8pBdaaubR4i8mRLTZT9vStGE6HgxE8T8gU3MK/9bhGLKz48qv7qJY36FNQ uzMg== 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=wepTYO8w6YbsFcNGVBbCvFTC7ov3ermwyIo9NfCllcM=; b=IB9RRTB8en8gqy2Nsy2MNcv03tlSMtthXT4IoiDnXxdcHFctWA5Be2Olexsh2ly0i6 Rhqap+GkljKfF3RzouK/G5l6h1pzfDhsI3jF6qt5caRl37jeg2jh/0TrfJLIyzCfqGyo HeCDXuzpSqhI23sZtEzvGyS6s6YAbuV4t/JUnSxYnqXzBxrfEoNasezzEbpfhjQEXtUU 1FMLmnNp0+A+wtAR24m0d+PXfB2iXmIYVhBmT650vNeLpLnKDhKLQ3xCsIRVWKyGNytH R31iBI7wLexBKgjRIoly0Rrk3HxUjluP7bAQv+36U29zoQNAgQJCJK3lkK7HGhMfQnz9 S2yg== X-Gm-Message-State: APjAAAValLw9UsORoM/Z5PnZe2Bi0HLW7pbMvt1Ic9zLl8wR3OHOwx0C 27cGdPCtAV4HA/Be7w4fZGwYX2YjE60= X-Google-Smtp-Source: APXvYqxy8q0yVVe+377nMfdxrg0sNlwz5C3Wg71IQuaMfaeytnFg8++wVxM1NxCI4tyFBA8J1obBsBYqUSo= X-Received: by 2002:a05:6000:14a:: with SMTP id r10mr118378wrx.310.1572445365361; Wed, 30 Oct 2019 07:22:45 -0700 (PDT) Date: Wed, 30 Oct 2019 15:22:13 +0100 In-Reply-To: <20191030142237.249532-1-glider@google.com> Message-Id: <20191030142237.249532-2-glider@google.com> Mime-Version: 1.0 References: <20191030142237.249532-1-glider@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH RFC v2 01/25] stackdepot: check depot_index before accessing the stack slab From: glider@google.com To: Vegard Nossum , Dmitry Vyukov , linux-mm@kvack.org Cc: viro@zeniv.linux.org.uk, akpm@linux-foundation.org, aryabinin@virtuozzo.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@lst.de, dmitry.torokhov@gmail.com, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, mingo@elte.hu, axboe@kernel.dk, martin.petersen@oracle.com, schwidefsky@de.ibm.com, mst@redhat.com, monstr@monstr.eu, pmladek@suse.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, wsa@the-dreams.de, gor@linux.ibm.com, iii@linux.ibm.com, mark.rutland@arm.com, willy@infradead.org, rdunlap@infradead.org, andreyknvl@google.com, elver@google.com, Alexander Potapenko 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 --- 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..0d00d2ac0c4b 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); + __memset(trace, 0, sizeof(*trace)); + return; + } + slab = stack_slabs[parts.slabindex]; + stack = slab + offset; + if (!stack) { + entries = NULL; + return 0; + } *entries = stack->entries; return stack->size;