From patchwork Mon Nov 13 23:20:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huaxin Lu X-Patchwork-Id: 13454719 X-Patchwork-Delegate: plautrba@redhat.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36014C4332F for ; Tue, 14 Nov 2023 01:52:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231172AbjKNBwL (ORCPT ); Mon, 13 Nov 2023 20:52:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbjKNBwL (ORCPT ); Mon, 13 Nov 2023 20:52:11 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E1E0D43 for ; Mon, 13 Nov 2023 17:52:07 -0800 (PST) Received: from kwepemm000010.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4STq2l5L5Hz1P8Gx for ; Tue, 14 Nov 2023 09:48:47 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemm000010.china.huawei.com (7.193.23.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 14 Nov 2023 09:52:05 +0800 From: l00564439 To: CC: , , , Huaxin Lu Subject: [PATCH] libsepol: add check for category value before printing Date: Tue, 14 Nov 2023 07:20:14 +0800 Message-ID: <20231113232014.48621-1-luhuaxin1@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm000010.china.huawei.com (7.193.23.169) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org From: Huaxin Lu In mls_semantic_level_expand(), there is a explicitly determine whether category is 0, which may cause an potential integer overflow in error branch. Signed-off-by: Huaxin Lu --- libsepol/src/expand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsepol/src/expand.c b/libsepol/src/expand.c index ee5f9185..9ed22bfd 100644 --- a/libsepol/src/expand.c +++ b/libsepol/src/expand.c @@ -945,8 +945,8 @@ int mls_semantic_level_expand(mls_semantic_level_t * sl, mls_level_t * l, for (cat = sl->cat; cat; cat = cat->next) { if (!cat->low || cat->low > cat->high) { ERR(h, "Category range is not valid %s.%s", - p->p_cat_val_to_name[cat->low - 1], - p->p_cat_val_to_name[cat->high - 1]); + cat->low > 0 ? p->p_cat_val_to_name[cat->low - 1] : "n/a", + cat->high > 0 ? p->p_cat_val_to_name[cat->high - 1] : "n/a"); return -1; } for (i = cat->low - 1; i < cat->high; i++) {