Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1862837rwb; Fri, 19 Aug 2022 10:37:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR5o4ZLLcIr+KNE2WJ43D1laJK+a6yfXaEfDvymcD3MAjEyNdx+S1qf/wbcQMOkJLwXCuv8d X-Received: by 2002:a17:90a:ab8d:b0:1fa:af75:e4ed with SMTP id n13-20020a17090aab8d00b001faaf75e4edmr15540164pjq.119.1660930664270; Fri, 19 Aug 2022 10:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930664; cv=none; d=google.com; s=arc-20160816; b=fdmMccaax9M23dGz+cpeDXMYkDk2DdNjrl/aWvF85ASE0piORJlDLR52baJG6Mkmdz Zuqj8mr/anose5ObMmfjInmxhzUav6Z9CEdrIeY3lwVmDpNMYYkpcPhq91fTNubr1D8m RlnuQLMzvKxPS7f5yZwbyupt6VnT34lzaDJPotNyPhfFGvEID/dj/6Bk7e73UBb26Xzb WTiwRMeaVUA/NobkZqrnCi4KsYMI7bOsI9dcQe9lKuEPn1X6Vw6nxRR0p3I9y9pOtrA6 RYseqZ/A0mRdwWmebrNFVEOFmHJ6GFjO+kB3sg2AdvpxVuG+bDsoecfIFdcOdmIQUHub m86A== 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=LGllQycjokDH19KAk+Q5X9Imnh3tnJbBsXUNku7ET7Q1sTYGD9f0FnOV1xVCoFjvV1 WockrMRf1WgRu7PAWgd6YkYUW3heoNcMK4fDj17L7/pwSRbBw1PftTsHmh3/DsZtu9Kn aj4YTug1ogkdI2lmDQRagFfL1+IYt/w8KwQi606My6znyIcWNP/eNVet2jd52CeToyN9 J/oZQdBVKvxb788XZjzq0FwMcUZmIijVd9EzoWo8ZtAInB8bPu5KhmkuIAIe0VRATI6l I/1v6gz4nRUjozMMBHKwBsYAMUocV4qBmpkahzJthb5dxC+9j6SRbiFxDUsqJjdLwKdC fpqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eGpTg6f5; 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 z27-20020a634c1b000000b0041c033e9f54si4393687pga.848.2022.08.19.10.37.33; Fri, 19 Aug 2022 10:37:44 -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=eGpTg6f5; 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 S1350844AbiHSP6W (ORCPT + 99 others); Fri, 19 Aug 2022 11:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350934AbiHSP4D (ORCPT ); Fri, 19 Aug 2022 11:56:03 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD8C510475B; Fri, 19 Aug 2022 08:50:49 -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 sin.source.kernel.org (Postfix) with ESMTPS id 7BEC9CE26B3; Fri, 19 Aug 2022 15:50:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78403C433C1; Fri, 19 Aug 2022 15:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924245; bh=VJCmYCac8+0GtJU2jX1P9L9/IdytulRpy/aYEWsiEso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eGpTg6f5kOOnlviCFETd3HvkVqiAQmn784zOTi/GdFGQpVxesXwlTGbl9zN88686d J/99kKE2gLArt2G5VJaT4NfcHm8Cr1kDRML+W+ekQsKdOU2N60EIDw+l6qNsRaxqZ+ Vnwp7kiAzw5N7U/nQbJNMaLu/bYQOnD6zfGChTtU= 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.10 105/545] selinux: Add boundary check in put_entry() Date: Fri, 19 Aug 2022 17:37:55 +0200 Message-Id: <20220819153833.987819975@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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