From patchwork Fri Oct 18 09:42:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11197967 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 2A8BA14ED for ; Fri, 18 Oct 2019 09:43:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E1A3F20820 for ; Fri, 18 Oct 2019 09:43:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GkHGImpL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E1A3F20820 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 150FE8E001C; Fri, 18 Oct 2019 05:43:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1019B8E0003; Fri, 18 Oct 2019 05:43:19 -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 017BF8E001C; Fri, 18 Oct 2019 05:43:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id D4C198E0003 for ; Fri, 18 Oct 2019 05:43:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 77A0D180619D6 for ; Fri, 18 Oct 2019 09:43:18 +0000 (UTC) X-FDA: 76056417276.06.ship27_74229d40f9a33 X-Spam-Summary: 2,0,0,b48b28dab49ff4a9,d41d8cd98f00b204,3nimpxqykcn8hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com,:glider@google.com:vegard.nossum@oracle.com:dvyukov@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:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3352:3866:3867:4321:4605:5007:6120:6261:6642:6653:7901:8603:9969:10004:10400:11026:11232:11473:11658:11914:12043:12296:12297:12438:12555:12895:12986:13069:13255:13311:13357:13846:14181:14394:14659:14721:21080:21365:21444:21451:21627:30054:30064:30070:30080,0,RBL:209.85.221.73:@flex--glider.bounces.google.com:.lbl8.mailshell.net-62.18.175.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:30,LUA_SUMMARY:none X-HE-Tag: ship27_74229d40f9a33 X-Filterd-Recvd-Size: 3953 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Fri, 18 Oct 2019 09:43:17 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id t11so2341505wro.10 for ; Fri, 18 Oct 2019 02:43:17 -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=qVGfiBfhzzQVnou2oLJwveorzbwo6gIrrMhVCSkMAIo=; b=GkHGImpLQ3EwRKwn7l/ZADn4OVLW423JyxDFc1LdBHQMA7HPpTP9LYR9WqXImI1U03 c3/UcJwjyXMvEQmDqQz6dNQdWACd8ALvcjFiLg/UqYH83RTi6ZEZzjGH5EKWA2kReu09 0cCmLuuoFx7CrUoRNz57xWwr+p2edFNTlAbSYZX7SDfwWxUG6qfVZw42TGCGAGSEtT4A a83wM9jW0ZmfXSXIPz6aswrU4H3hYKDL8XGJynoXzdcdD2fw5my0lTPuJQ3nCUroL23E 5QfnSe7XvOjYxZNIMZSAVhxKOsi/+/XkjwIZni/DvVjughveQILrBtvHCDs2uh0O7qwR iDjw== 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=qVGfiBfhzzQVnou2oLJwveorzbwo6gIrrMhVCSkMAIo=; b=F8KdgTS7O4UcHVF/2z7G0j5cIJuLXqcEhk0rvZGyNmU36hjtJx5Y1cSKpJ9q7lEySV SwiNizLzx9hOovIOw1YkAYAwaMeGpnD+XDBJJBCmlQBPSJvdUCTjVqWR85oOsWkCtFHt zMR7IyN2637Re/Cwap5TJU8Wqj+IfwFFECP3Yhmgo2TmOmR37vKGWTNsAU5cR+Xw0pPf JV7RxW0YEl6CyV0SC3mxo3Q4DCZYrYEtVZETOge4le2YLJp4WWVMRufFrToibgd979wk nfMT1TsoIaq7Tkxgq+UC98MrNUdjAOGvFc4usxIWrGPyXcESgtny9hw0bBk4rCFZwQep xPyA== X-Gm-Message-State: APjAAAUZP0lYSd/T0d7mSnleWfBrtyVaF03qkWfU76KgN2Atd1gqLAfe RJulpIqGHqvmvRQUuVN1WTYYZaiQwO0= X-Google-Smtp-Source: APXvYqwaWTNi0Of8RXmiHbm8De8QIudp9h9GWyZYJ7B+VS6uSbe2nnu5rdh16diWDy6Kw/3c1jGdAzVwDFo= X-Received: by 2002:a5d:6246:: with SMTP id m6mr1325165wrv.262.1571391796358; Fri, 18 Oct 2019 02:43:16 -0700 (PDT) Date: Fri, 18 Oct 2019 11:42:39 +0200 In-Reply-To: <20191018094304.37056-1-glider@google.com> Message-Id: <20191018094304.37056-2-glider@google.com> Mime-Version: 1.0 References: <20191018094304.37056-1-glider@google.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog Subject: [PATCH RFC v1 01/26] stackdepot: check depot_index before accessing the stack slab From: glider@google.com To: Alexander Potapenko Cc: Vegard Nossum , Dmitry Vyukov , linux-mm@kvack.org 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;