Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1164771ybf; Thu, 27 Feb 2020 06:11:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwvsmR4tv/Z9l1NKBGt+6EGoS4kKE9kK+AI30Pp5w+xME5D0JqDI9BSdEo9LnPmg9EHt4Pj X-Received: by 2002:a9d:4c06:: with SMTP id l6mr3554777otf.161.1582812691600; Thu, 27 Feb 2020 06:11:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582812691; cv=none; d=google.com; s=arc-20160816; b=m+Pfcdt7euk1/VHlCO7RtDnnmE6v7qZeohYAC4KAY3D0G49FZwJSgD6pYDLDe6IEQN 0euxohkZ9YZZHfcq50TmBY1buCtLTzEds8HMbygRafLxAOXNUgXmqeFeFMVgbnwT7MRr ZCDtVzfOFajRhtJaUa3EiK8EQZc0Jo6rKocr6FiJWs7j/tV8fdkxlMYp7TVDpkxnRWd8 pvicFwQJ4/uvi/o4p+P+sRVdYckYaPTUQSQV8Rh0HIfb4AGENq2JEpUFxmMTV2/Tp3s7 8eLs/yz8JxDLnICnDyJrtVxJaSXZKGSPkige6UFxKQrfSOsxRG+2HA8840MJuGQgrPJA gxDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5RcEsL4sfjecnGWh+NIiUCZaFHal2MSE+Mq/LNm5uic=; b=m9aA7p4rPXR0xtndm88pr9Em72oXGaO0vUGZY1rXNQLsT82Pv80rDaZC490YMv5XPN Y7hf0F8XRk8gVNW5MFSblJIuWJdk3uhdjk1TiSrMmcDkuxtBP+VNLqtSJAncOCMHY8VW 8ov9+Fsy8KavXihEmBT5JfeWx0RyGe1y+jPsJccVNC/wZkJCoXRUDUKKzusuSYOdWm3a qtLFKe42FyhZIx6c6jMK1LL6G9l+m028plXF4tjypa0M3DJ+HNvJHa7t5ar51UsbE4Lk 4DNjRCgrrXPLxJFP17ZHDoHUkd3ohTtscFKaXixJuPDsHVc6FKf2ZOd1JNotcj7efyt6 qMBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0MZsJgpW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l22si1501657oie.32.2020.02.27.06.11.15; Thu, 27 Feb 2020 06:11:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0MZsJgpW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388395AbgB0OLN (ORCPT + 99 others); Thu, 27 Feb 2020 09:11:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:49538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388039AbgB0OLJ (ORCPT ); Thu, 27 Feb 2020 09:11:09 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 89F3920801; Thu, 27 Feb 2020 14:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812669; bh=rSno5SUfmCP36VHtQNRPA3Is3Vioa+Kv64tv2eG8qRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0MZsJgpW77t2vQ8U2j6j/EVzHe36hbgc1xzJOSRraFIWLudACKdFo2iGCbY44znrR gjUbuHICRUq3BvyFN1Oh8J2JtzwLLN7gMDi8RSXnV6yjQPgDE9rZZ5tNgdC+8Xsqb5 SyDqQGiID4fNADCYMKJE8d2fABymVz4LLXV2Lves= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Potapenko , Walter Wu , Dmitry Vyukov , Matthias Brugger , Thomas Gleixner , Josh Poimboeuf , Kate Stewart , Andrew Morton , Linus Torvalds Subject: [PATCH 5.4 068/135] lib/stackdepot.c: fix global out-of-bounds in stack_slabs Date: Thu, 27 Feb 2020 14:36:48 +0100 Message-Id: <20200227132239.505540272@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Potapenko commit 305e519ce48e935702c32241f07d393c3c8fed3e upstream. Walter Wu has reported a potential case in which init_stack_slab() is called after stack_slabs[STACK_ALLOC_MAX_SLABS - 1] has already been initialized. In that case init_stack_slab() will overwrite stack_slabs[STACK_ALLOC_MAX_SLABS], which may result in a memory corruption. Link: http://lkml.kernel.org/r/20200218102950.260263-1-glider@google.com Fixes: cd11016e5f521 ("mm, kasan: stackdepot implementation. Enable stackdepot for SLAB") Signed-off-by: Alexander Potapenko Reported-by: Walter Wu Cc: Dmitry Vyukov Cc: Matthias Brugger Cc: Thomas Gleixner Cc: Josh Poimboeuf Cc: Kate Stewart Cc: Greg Kroah-Hartman Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- lib/stackdepot.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -83,15 +83,19 @@ static bool init_stack_slab(void **preal return true; if (stack_slabs[depot_index] == NULL) { stack_slabs[depot_index] = *prealloc; + *prealloc = NULL; } else { - stack_slabs[depot_index + 1] = *prealloc; + /* If this is the last depot slab, do not touch the next one. */ + if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) { + stack_slabs[depot_index + 1] = *prealloc; + *prealloc = NULL; + } /* * This smp_store_release pairs with smp_load_acquire() from * |next_slab_inited| above and in stack_depot_save(). */ smp_store_release(&next_slab_inited, 1); } - *prealloc = NULL; return true; }