Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2855055pxb; Mon, 4 Apr 2022 00:18:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAff9RjcebVuhmR+DbXrvQobDgGogRetuJQpKGhbqi/oE5Jt8KqLTtIBZ3WI1vrMSAJ3bQ X-Received: by 2002:a17:906:4786:b0:6e7:f7ec:632 with SMTP id cw6-20020a170906478600b006e7f7ec0632mr1140100ejc.751.1649056721051; Mon, 04 Apr 2022 00:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649056721; cv=none; d=google.com; s=arc-20160816; b=zjq4rCrkcx+ffSKd1UCZ/obGdvxXErcDXSHAtffv0YLzBjxHgLQ6wrmiBRHyPkJph8 sCOd+TBmundX5IJBBbsURvv8Ob32wupwpg8WmsOCxANW2pQevKjYcnHhYdfXR5zLVBPz EObmBPS8HKorIU2C/CTP3CF9MCYYd+89inM40zuzRojSq2AQ41yY5F6aRFLSlgJgEzYX t+XpD1VLqYf46wO+nglyLY54O5uQuLiqyX8NwnI5SiNTLe6d3dOa8gmwzX3QIhW9fHDD GiyWZZKb9l3hfMjSqUln8kSe1KbQeeSIV6cYzVjP7K7PNyVFwi6pqaxfvA6qH4jm2Hjo Mf5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Oi5jHDsfj1W8e5wC6wSv6EeGk4/bkK+tg+Ml77lRfPo=; b=PFDPOstZUQ9pqcLEu+r0YhgdH4nbAbABZbiA6bDsK4VNZ8x+rOp3vOZFa9Lo8tHWsl VqH3+dpNzujj1o62rlyweI90BpJjiB0Jk5FQ/QntPXYvUI2ImJZSoH1sF7OhHEoEE5Ob kwsSqRGHuszzbKdp6AffockfVrEZQTt5e+m7fc+J1MH21g4+o0E/zlBhcseF6bmF0GZz Ym38dt86Hd6hfJYy+BFjTa61m/mOUj2aZdYsilts+r3XmdJzljjbZw22zzAjOXb2ovo1 Tv1uAurG37HTjbJzdjhmAyM9C492APW2eNqOnu16JIaPhkoyX/Ar0e5s8ba8y2TirnJL unjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="NKIRTH/0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q9-20020a170906540900b006df76385c90si6195664ejo.304.2022.04.04.00.17.55; Mon, 04 Apr 2022 00:18:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="NKIRTH/0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348343AbiDAOmz (ORCPT + 99 others); Fri, 1 Apr 2022 10:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348466AbiDAOe3 (ORCPT ); Fri, 1 Apr 2022 10:34:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A7EEFEB; Fri, 1 Apr 2022 07:32:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DA55361C50; Fri, 1 Apr 2022 14:32:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F35D1C34112; Fri, 1 Apr 2022 14:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648823559; bh=FuCO+U6N9ZCghCVd1CqTy9TOpm50qfLHeScE/HPLP+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NKIRTH/0iIw9Volcgp6mJTNKIMxqmSae2w5+satehUDLj14OqvGtUkaS4Ef276le4 I3YFRvxq+OMufsQTWGSH32BnDlGN9vTYjJcITcv1AN1O+JElYySJER0D11C89LK5rw SPHVXLSgM1JJZazOfj2f4RMnu7gEBuH0Ds1RT3k12sE7j+n25+qM29MvWxLOTDpQa4 FROpJkB75izWPvxLzLpjN08666dT6gnlsysfYb//6C+USNYicfYY2r5IbsompSxpuZ a2mnSMwCt4pbQaqTMGL1E6I7VRCTlWQYLbslx0XjQ8nMz0nbVR7xJOAr36KSC19J6i GZ/xcWkXXC1dA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wang Yufen , Hulk Robot , Paul Moore , "David S . Miller" , Sasha Levin , kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 5.17 144/149] netlabel: fix out-of-bounds memory accesses Date: Fri, 1 Apr 2022 10:25:31 -0400 Message-Id: <20220401142536.1948161-144-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401142536.1948161-1-sashal@kernel.org> References: <20220401142536.1948161-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Yufen [ Upstream commit f22881de730ebd472e15bcc2c0d1d46e36a87b9c ] In calipso_map_cat_ntoh(), in the for loop, if the return value of netlbl_bitmap_walk() is equal to (net_clen_bits - 1), when netlbl_bitmap_walk() is called next time, out-of-bounds memory accesses of bitmap[byte_offset] occurs. The bug was found during fuzzing. The following is the fuzzing report BUG: KASAN: slab-out-of-bounds in netlbl_bitmap_walk+0x3c/0xd0 Read of size 1 at addr ffffff8107bf6f70 by task err_OH/252 CPU: 7 PID: 252 Comm: err_OH Not tainted 5.17.0-rc7+ #17 Hardware name: linux,dummy-virt (DT) Call trace: dump_backtrace+0x21c/0x230 show_stack+0x1c/0x60 dump_stack_lvl+0x64/0x7c print_address_description.constprop.0+0x70/0x2d0 __kasan_report+0x158/0x16c kasan_report+0x74/0x120 __asan_load1+0x80/0xa0 netlbl_bitmap_walk+0x3c/0xd0 calipso_opt_getattr+0x1a8/0x230 calipso_sock_getattr+0x218/0x340 calipso_sock_getattr+0x44/0x60 netlbl_sock_getattr+0x44/0x80 selinux_netlbl_socket_setsockopt+0x138/0x170 selinux_socket_setsockopt+0x4c/0x60 security_socket_setsockopt+0x4c/0x90 __sys_setsockopt+0xbc/0x2b0 __arm64_sys_setsockopt+0x6c/0x84 invoke_syscall+0x64/0x190 el0_svc_common.constprop.0+0x88/0x200 do_el0_svc+0x88/0xa0 el0_svc+0x128/0x1b0 el0t_64_sync_handler+0x9c/0x120 el0t_64_sync+0x16c/0x170 Reported-by: Hulk Robot Signed-off-by: Wang Yufen Acked-by: Paul Moore Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/netlabel/netlabel_kapi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c index beb0e573266d..54c083003947 100644 --- a/net/netlabel/netlabel_kapi.c +++ b/net/netlabel/netlabel_kapi.c @@ -885,6 +885,8 @@ int netlbl_bitmap_walk(const unsigned char *bitmap, u32 bitmap_len, unsigned char bitmask; unsigned char byte; + if (offset >= bitmap_len) + return -1; byte_offset = offset / 8; byte = bitmap[byte_offset]; bit_spot = offset; -- 2.34.1