Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3019375rwb; Mon, 15 Aug 2022 16:16:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR4LtBz8Qix83HEyx5HCQ+4Zxcy0mPZ5PwqNJTeZZI0kowiM3oBvrmpRlcxLNvwfMX4hp0E5 X-Received: by 2002:a17:907:1c8f:b0:6e8:f898:63bb with SMTP id nb15-20020a1709071c8f00b006e8f89863bbmr12268824ejc.721.1660605376357; Mon, 15 Aug 2022 16:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605376; cv=none; d=google.com; s=arc-20160816; b=g0VIctYhLYFiYNA27MIvmB8UY2UMrOsJcNsKrvVF4Zuhf4kkNCH+7C9f6JwxoOZ1jY oF0UVuMU4MeY5DkE7RglyQBIBZIxX+aWzXrVBKvE/a+bWFmfUYCC9YZUNg9l/C8Vsyyp +kIQBMZWckf0YzaaVpFuq8kkrjMZ3RMYpTT7YE8PRsWw59cCj9PP502OXEJh2N3gTDEN pIBstkNHqkBz68uMLX4ozgpzDtZRm5SNaPdw8rYU0MQHfSCOLFT10NI4klxnw6d7yktx 1xq4ZbhkuYt9unbseI+CNV5vTWcJKck6reMydzVHz+l1mOV76F99eL7bVlBy8Mnzxh3s TRiA== 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=p4bs8k5JyOakpLdFUy6V3q7axNAALg7Kg5zM97scVc8sdiVQGvTjaxdR9uIR2D6ofy jul0rJF05HChUU1Fu/E7KO+IuBHJKdHuMp0VH1aHBSNovLRt0ePGGMnWN6pYtBeUs9wG H3l/anZjmUzKhT9iCD6p5MchnKWlnM1qQ1StrxkBAzAB8CXb9CPyf4LhdYwaZBiKrFll bhquiF85M/p+j1cPcmjp/EsuHd+UMFs38LQkvIPUStV02kpKO6AbivKjKhvZLZmNRLQ/ J6RXd9UtwWVTU8EhlSzw61WD1s0Ko6cQ7XAzGTPJxWWfRHbxfNlZdfRF3XeaQUdkK1fw h7VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XjbW+k7h; 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 z101-20020a509e6e000000b0043bc778b19asi8834480ede.166.2022.08.15.16.15.51; Mon, 15 Aug 2022 16:16:16 -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=XjbW+k7h; 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 S1351250AbiHOWln (ORCPT + 99 others); Mon, 15 Aug 2022 18:41:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350829AbiHOWhM (ORCPT ); Mon, 15 Aug 2022 18:37:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57067F580; Mon, 15 Aug 2022 12:50:34 -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 872596125F; Mon, 15 Aug 2022 19:49:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E702C433C1; Mon, 15 Aug 2022 19:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592970; bh=VJCmYCac8+0GtJU2jX1P9L9/IdytulRpy/aYEWsiEso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XjbW+k7harS4zQKEp1O7nJEaqMN5/Idc5JGteMviflf06SXNqAczMdcRauImmNbCJ 9z0KVKS1fwQ6a7JG20k/lOjzUMmPr0sirBdZwy5VuBe4XGPr1Z6z3mIwZbUXmViWIr 5+lv5auYH24qrOzi0U6y4sjU7rS+h2mZtiFATUrA= 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.19 0194/1157] selinux: Add boundary check in put_entry() Date: Mon, 15 Aug 2022 19:52:30 +0200 Message-Id: <20220815180447.494296967@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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