Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2927404rwb; Mon, 15 Aug 2022 14:12:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR4bwUmyrkoNAKjWjHvOjaAN5EpO2nPltelrf2hatHGdfqwRCsJ5FXsk40ruHcjzVu874WN9 X-Received: by 2002:a17:90a:d783:b0:1f4:e30b:ece with SMTP id z3-20020a17090ad78300b001f4e30b0ecemr20634548pju.165.1660597970095; Mon, 15 Aug 2022 14:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597970; cv=none; d=google.com; s=arc-20160816; b=qUmTqUz7/PmkPL+aa0WlFaYSr4dL1f2pNbG62z/btPKjhq0Dzsk7GMjntRvuRciXI2 l+xYWzHFUDed2uONK63RQUugdipaxuE2bg4ozjz5pJLr0azmv3zExkDUZique9xtn2Zs zgDVaV8Uksc1R0IMC1XeZdsOioJRFkH7AzshRmMCHmZGf6aA7j/BXFQqhSZJ6/OtZvtN bZhAYSNgOcgRsVyUVdMgOoeUkRA8wBX76kw2r47jQsFPomFtmDKCtdzlFum2TMvRXDo+ C3uwV5YvWLd+aP0iRszuk3pXexHTjjbgHrHW0X0w/EXj6SavD/O2TTB0vfCvm88N3ZtG rEeQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4hYuSIb3K2i/hxHsHVN5/6OuG2w4hW90jNIyRttlgVw=; b=dUl4nMAXISxMkKiV8AL70rolykPhI4PvAp4buYlAufXq5WPrQ9VvjkF4VLzh7vc+0g w5cESxS7k2/YfJK8vGy5hGWSCub4D7d2oKyYZbXArc+qH3h7kq9HrV3BOaNGoSAD5t9A LJqQz4TVf8a1clA2DmM14t1meV264ziUQQSApy3ymn6jmbQwmssj6CRZWQ5HCm7ruspI Fr6xmC7rnsHQXX1OCrWfgfUU4B/QBOMGF1yhF+BiQhA1nVaulPbydrsmjvmo49mpRv6a QRThRybUWXC6gY6ULHLAj16VpUsyq7Dx3/yhsjDVZUGx7itpMcUZB0Ds1wLKcI2vgME+ L1Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="xB+4q/Pd"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j23-20020a17090a841700b001f3e1e8f91fsi10851321pjn.22.2022.08.15.14.12.39; Mon, 15 Aug 2022 14:12:50 -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=@linuxfoundation.org header.s=korg header.b="xB+4q/Pd"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348023AbiHOUb6 (ORCPT + 99 others); Mon, 15 Aug 2022 16:31:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347525AbiHOUZz (ORCPT ); Mon, 15 Aug 2022 16:25:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36C6D9C225; Mon, 15 Aug 2022 12:03:17 -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 ams.source.kernel.org (Postfix) with ESMTPS id ACFE3B8107A; Mon, 15 Aug 2022 19:03:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05940C433C1; Mon, 15 Aug 2022 19:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590183; bh=VJCmYCac8+0GtJU2jX1P9L9/IdytulRpy/aYEWsiEso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xB+4q/Pd+DDRqUjc94LIz9JwVT8mNi3NQUrAXZ2mYotMUEkRC4KX6HSRm+ZVii3II Xvz72sGB2k37E4C1td7+0z5diWc2ZaUVRYGDX8rxapAy2wlZkNCSzXv3/wzKPbj77b /AtaRAOqm21RAn2PQwwOYPGgl/IvtdFptnGGSDoY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiu Jianfeng , Paul Moore , Sasha Levin Subject: [PATCH 5.18 0179/1095] selinux: Add boundary check in put_entry() Date: Mon, 15 Aug 2022 19:52:58 +0200 Message-Id: <20220815180437.044913329@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: 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