Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2872170rwb; Mon, 15 Aug 2022 13:02:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR6irtaVSMNzzrwc5vAtXFDlB4NR1PShpIR4onOzkL7ADGA5jmift9vX1XWmbN+YO3ttudw8 X-Received: by 2002:a63:f02:0:b0:422:9156:84ba with SMTP id e2-20020a630f02000000b00422915684bamr13379835pgl.137.1660593772422; Mon, 15 Aug 2022 13:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660593772; cv=none; d=google.com; s=arc-20160816; b=BTN5Coa+7U16ccR7+y+lof6pzRGDtGWvlovMlvl+4sU3GZz5lnC7zJV0UaVZICcVWZ 1nuicwpTrKn2OkquGA/2upSKTPMoSlliH6BpiavPMa+vjIFVxyxqaHUbePwks7R/aaH8 cXvtfc2ucOEyyC4hYMYUFkpFRM6DuQx1T+AWSEzDH18UyJ4D3ATILqZ2J9nVuMm3vbZ8 mwqMbWTjI4632Pewqe7X13JyZS6aAZ019MKbB70J280U7gXOWComHuySS6pwNzGp6Tl2 lqaxYwX3hjtj0XNeQc9JYHB07lbnKseisOEmW7Yt+jEWablmDoCJ5zY5SRdAW4oi7MY4 Juiw== 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=VTN0E0vOSW2O+5UXVkt8Yhu18Ryb299IwPS1r77U0R4ZmRkbjiH2NrNWkthOMnEF4a Xbw+qoa9kwvDyFnp+RfVO+zrdjdlzt/12HPKxXmXkUFat8esoPl//a55bFXJLVZ4iBnX uZh48/y6UBRL7sdrVwwQZvwBxhuPhllhp+TTPn5LohuUhB8knEXq3uKDqQlxdSGTBHUC ILoJ0phhO674CxrcoH+5b+wNxMtddwjpS9kwivzifCvy7a19iarWMQ8ByAMIxcCcjG0C UeUInbDmPwEHfVnPXvsjD6GezmUvFS4x8X+4ikR96/PrK/aFBv6XIWvYDXhkXzFcdccr PVpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1S3JwEsJ; 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 rm11-20020a17090b3ecb00b001f50c96fe7bsi11868888pjb.62.2022.08.15.13.02.40; Mon, 15 Aug 2022 13:02:52 -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=1S3JwEsJ; 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 S243244AbiHOScH (ORCPT + 99 others); Mon, 15 Aug 2022 14:32:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243483AbiHOSbN (ORCPT ); Mon, 15 Aug 2022 14:31:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77E9432D81; Mon, 15 Aug 2022 11:21:08 -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 CE83EB8105B; Mon, 15 Aug 2022 18:20:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36EB0C433D6; Mon, 15 Aug 2022 18:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660587648; bh=VJCmYCac8+0GtJU2jX1P9L9/IdytulRpy/aYEWsiEso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1S3JwEsJaH5ZCS8UzOBt14Q015LN18ciXY40KMajlTOLMwceN0S93o/dJpiN8eVaQ XB2+08VXwyueNBJ8rTj4WmtQ5Xm6X99ka4uvK6BlD0fWF9YIvrFvTojfwicVX6P9vh 74LgyZy1yGKlnQMdRu2YDk7dRRuEYc3ID5VyM1SU= 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.15 149/779] selinux: Add boundary check in put_entry() Date: Mon, 15 Aug 2022 19:56:33 +0200 Message-Id: <20220815180343.681170622@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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