Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4256163rwb; Sun, 7 Aug 2022 19:30:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR5bnzbtDjfLEDIECrfthdRRVeXmQ5PC5L/AHDIwW0AxF8i/qFbdVFdp36ILchEC2Lzy8p23 X-Received: by 2002:a17:902:db06:b0:16e:e5fc:56d8 with SMTP id m6-20020a170902db0600b0016ee5fc56d8mr16951331plx.100.1659925843516; Sun, 07 Aug 2022 19:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659925843; cv=none; d=google.com; s=arc-20160816; b=Cb2gkx9JFKZMqqsf1IruRYfkxfro8YaZE3xL6vuJRmL2IwMxApkfVLk1AvsQuKOne5 +KDC1nvGCh1aUSTk6ipc1opZvvHDIHTwshIf12lmfEtfCJJrBVmenW24jcfxR4iQc3YZ FRMxYEASQjFuDG8AfLYd29U46xlR2AbzkezzTHlCNwJyFH3OKTlTzI7vUW5pX13us10P /6mp1WFV9GyixbhquoludYOqHGEav4SIQef2h9x9JZNyK9XGR+Fm5TePIVXPd8vMgWVf BNIXofF/eAbHb/6brC4H4nf4dpPpQFygNVwyQ5qrBc86XGYb7mOsQGDHaIxXG7u/H0Za CkeA== 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=4hYuSIb3K2i/hxHsHVN5/6OuG2w4hW90jNIyRttlgVw=; b=LjsQ2aSfpyJRdC+xKhBnfSTfIFKkaKc1CzB9cXWGza0bzk28GCHWLd8tf5soSjXPZl NSm3YHOjkQV6hXONKZmfiTq/Iok94ZF56z9ajKFlqIM5WggtH29I65xL1s2P8u+HNISw OBwKzXyZEWHQTIJQ3lYVID6T8Uwk1z4AyxpPGoaLCKjFgmu1AJeqiIFszf2VLX0J4fXg JD1oCEYQ2NgNUDLJd1BURUJi59P/nCRqiGcerMbDZvOx7hNDWZE/0778QnxOvgchgQni zhsjdi1x8eCrxpOnu3F9VdO7DsPWShuGfmUW3CYg0yIsZzYon7SstuytcbI8pWAkiFiG sCyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U241++5m; 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 r12-20020a632b0c000000b0041d95d805d5si863786pgr.53.2022.08.07.19.30.29; Sun, 07 Aug 2022 19:30:43 -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=U241++5m; 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 S242015AbiHHBiT (ORCPT + 99 others); Sun, 7 Aug 2022 21:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242474AbiHHBgu (ORCPT ); Sun, 7 Aug 2022 21:36:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B511FBE31; Sun, 7 Aug 2022 18:33:38 -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 51BCE60DB9; Mon, 8 Aug 2022 01:33:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D50EAC433C1; Mon, 8 Aug 2022 01:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659922417; bh=VJCmYCac8+0GtJU2jX1P9L9/IdytulRpy/aYEWsiEso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U241++5m7O03Qy5CYM056QlRGhhkm3HhSrLFVMRhX9AmqjgaX3SdbG4vSqC3X5D2D mwe2NLbyzjteUa2vW7b9p1wuoJIDE/Y6CcPRI21NgH9+rxFb9I4/XHqt8cPTjd9egj t62YlQkYoeLin1hEW+zKNtDp0IgfyaxaDgBgThQFU1r25llhXvTzG3QfpRhjHeN4I8 vrE6ewBgbYBuFC0uVBHOk3wjTZIsdtDcgehGGjOrCUEzSCPSp3sRN1WdOiCCsVKNms 6fUlSY2r/vTNZAMCnDh8eBrxK1ZG/Ql6yMJBQUaUxeh7+2wrSMVTrb/0MRIFBEndiw xzt1UnE++5SMQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiu Jianfeng , Paul Moore , Sasha Levin , stephen.smalley.work@gmail.com, eparis@parisplace.org, selinux@vger.kernel.org Subject: [PATCH AUTOSEL 5.19 54/58] selinux: Add boundary check in put_entry() Date: Sun, 7 Aug 2022 21:31:12 -0400 Message-Id: <20220808013118.313965-54-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220808013118.313965-1-sashal@kernel.org> References: <20220808013118.313965-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.7 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: Xiu Jianfeng [ Upstream commit 15ec76fb29be31df2bccb30fc09875274cba2776 ] Just like next_entry(), boundary check is necessary to prevent memory out-of-bound access. Signed-off-by: Xiu Jianfeng Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/ss/policydb.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/security/selinux/ss/policydb.h b/security/selinux/ss/policydb.h index c24d4e1063ea..ffc4e7bad205 100644 --- a/security/selinux/ss/policydb.h +++ b/security/selinux/ss/policydb.h @@ -370,6 +370,8 @@ static inline int put_entry(const void *buf, size_t bytes, int num, struct polic { size_t len = bytes * num; + if (len > fp->len) + return -EINVAL; memcpy(fp->data, buf, len); fp->data += len; fp->len -= len; -- 2.35.1