From patchwork Thu Nov 9 13:53:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13451111 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 20ED6C4332F for ; Thu, 9 Nov 2023 13:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232307AbjKINxY (ORCPT ); Thu, 9 Nov 2023 08:53:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbjKINxX (ORCPT ); Thu, 9 Nov 2023 08:53:23 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC99272C for ; Thu, 9 Nov 2023 05:53:21 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9de7a43bd1aso141778666b.3 for ; Thu, 09 Nov 2023 05:53:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1699538000; x=1700142800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=S3uhkNhG9mnw3UfxlqxhiWF6b2P/LIFOZkukQVAxPEE=; b=YhJq5FAHCi1PDLHhBXysphWBfCBL5Z0/oROr1Ini1Ca3BtaEnbuy9JS72lFXf3b/Q5 AGESmIf1gxDzkVdK24qa60DBMdb9brDGMV+4ZRk9qh8f7sxpoUUT7au2Xv8aq4rWz0pT DrYSyQdhKGIPhKdxRD1cvkoYUIkbxQdSfPpBq1uzJbh9sWCUINukPbxz+Tc+lBalTyzD pL4cO8elyBfj4Eus1qBRlar8aFvQX/v7SIEeP3nshlG1q9D5mKEy9sUWTjxC51r5qGDm oREc8BAbl4PjRGK99dbKhdkAwZ89dahuq8v38tMC6VXhftrFOnTtvyQlP1cpqpiGi861 89rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699538000; x=1700142800; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S3uhkNhG9mnw3UfxlqxhiWF6b2P/LIFOZkukQVAxPEE=; b=MVNTGk/JTiYKl97eWAb7WvsfyVRgw33LtMGn2WATfcabisI7mvH+5wdkDW4DO/cndN TNrm+uVhbHHDOPnr3PFAi8W8JrOClNxdI5Ufo5ahT3trqif1NuQWv+AX0xzTZqDHIQIx LsKyoIoc536vYI6Pjit+HgRInBzfJSrKEXT9hFsoxJdSjSpX9lxUDB5m3xdMc8mM5FYb rq9rN0SXvAH8eUU/TcV978pu5wooa83xFiLkP6vkwJBb+04B9bUATGATdEhTFBKQstCV BGDnMljOy1+N3KV+wihaML60UU/ppYaBvTh7KARxJdTWE6ejsK6SykrzHgVK2SRoQQ3/ 3ktA== X-Gm-Message-State: AOJu0Yz/qHlEqdyG3Qdc4N1sDWffXKSla2FORWfLCLHbvBTFYcv3ucYo hi/p3hK2HWQJKDvNrRdur+ep8v4z/AM= X-Google-Smtp-Source: AGHT+IE2cZLi4jUC01dsJjeJhH94TZZx/EIg56kJEUstzhAxg1pkoZ6sbOUjMhq++mCBRDRv1FdAtA== X-Received: by 2002:a17:906:4789:b0:9c6:287d:c59d with SMTP id cw9-20020a170906478900b009c6287dc59dmr4606533ejc.28.1699537999843; Thu, 09 Nov 2023 05:53:19 -0800 (PST) Received: from debian_development.DebianHome (dynamic-077-000-043-071.77.0.pool.telefonica.de. [77.0.43.71]) by smtp.gmail.com with ESMTPSA id q8-20020a1709060e4800b009de61c89f6fsm2549900eji.1.2023.11.09.05.53.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 05:53:19 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 1/5] semodule_link: avoid NULL dereference on OOM Date: Thu, 9 Nov 2023 14:53:11 +0100 Message-ID: <20231109135315.44095-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org In case the initial calloc(3) call fails the variable mods is still NULL while its size hint num_mods is set. Reported by Clang Analyzer: semodule_link.c:182:29: warning: Array access (from variable 'mods') results in a null pointer dereference [core.NullDereference] 182 | sepol_module_package_free(mods[i]); | ^~~~~~~ Fixes: 63e798a2034a ("semodule_link: update") Signed-off-by: Christian Göttsche Acked-by: James Carter --- semodule-utils/semodule_link/semodule_link.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/semodule-utils/semodule_link/semodule_link.c b/semodule-utils/semodule_link/semodule_link.c index 0f157bd9..58fca34d 100644 --- a/semodule-utils/semodule_link/semodule_link.c +++ b/semodule-utils/semodule_link/semodule_link.c @@ -178,9 +178,11 @@ failure: ret = EXIT_FAILURE; cleanup: - for (i = 0; i < num_mods; i++) - sepol_module_package_free(mods[i]); - free(mods); + if (mods) { + for (i = 0; i < num_mods; i++) + sepol_module_package_free(mods[i]); + free(mods); + } sepol_module_package_free(base); return ret; From patchwork Thu Nov 9 13:53:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13451112 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 9E586C4167D for ; Thu, 9 Nov 2023 13:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233828AbjKINxY (ORCPT ); Thu, 9 Nov 2023 08:53:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232167AbjKINxY (ORCPT ); Thu, 9 Nov 2023 08:53:24 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B6402D5B for ; Thu, 9 Nov 2023 05:53:22 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-9c53e8b7cf4so149013366b.1 for ; Thu, 09 Nov 2023 05:53:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1699538000; x=1700142800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=aULkyJIGRGALtv4xtIeKpu861oBjEsk1XeiBonlFgUw=; b=H0rkPhjsHs6deVJvgg4m4wL/XQUDTeNUWLuXaXBKRBXQUvX3p7ihnbVWwjzwPipprA zBVtaEWuJmAWzOKHvF+3FH6y7ksfgo2PLGrZCCRkckbn/kiYmxqnezMmSybADAFAS17W EhtXT9IBRodJ9YiyuOnM/EdetfMGkV4Z1RQbhnn6T1Rd9+QoyvIHREveIl2kFVJ3CAuM As/6rRmyfzHeKoPtUKinRSUtdm9blsbonNYXjdwvnXAVxMf0M8N0R8kMa3fIXW5EhEOk m69AMeMeXk0SDwznVyyUAmWBOsJ92Q3ZDNvWcOJQBfuA5hWi19cxRo0SofLqYS2qfvgJ ANPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699538000; x=1700142800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aULkyJIGRGALtv4xtIeKpu861oBjEsk1XeiBonlFgUw=; b=hON+qX0z6AAqh1l3gFvncGPrEJcZQaHu4Wfwp20mJnwd3qtV+cGgORXg2d1BPbhXKi uaoG34keuaXZ9bEGTFYsEnXgw5jTFi22UPxVbz7uiF/AVXpDmzfhoc1OyTYMX9DteKma TQyrPjJgj3XelIsTpZnu2e88TULaF9hrR8ot2xAtx2j6F2+JUV8YqIBpCCBRCSr/O6Uh mLq0I5Eidy/yA8l7VciQ1YVNQbd/YxoHkeSHlBOC4PI7UFYe7pOFvh6NtUvH+qDhPgH9 pFTogFtgsQIXhN5VUU8X4+T7+9vmSiz3yWjTZERxIIixVo9KDIM0V6sFNC9B1Ytz6un7 icVQ== X-Gm-Message-State: AOJu0Yy99TY06EycR4M/N0KSSBk1PCvwN3F8J7vnCk5GAIzbXUXyifJh mtNIp0e/TlLDaHVcpVaZrnXvz2UpIhY= X-Google-Smtp-Source: AGHT+IF3pyOvzC2qHR7r3dwwVgQy/YMEwTgZMKo7+Ic3Xf0AGYjzieoATGeXxlok3It5CT7j2mk8uw== X-Received: by 2002:a17:906:794a:b0:9c3:b609:7211 with SMTP id l10-20020a170906794a00b009c3b6097211mr4434288ejo.1.1699538000396; Thu, 09 Nov 2023 05:53:20 -0800 (PST) Received: from debian_development.DebianHome (dynamic-077-000-043-071.77.0.pool.telefonica.de. [77.0.43.71]) by smtp.gmail.com with ESMTPSA id q8-20020a1709060e4800b009de61c89f6fsm2549900eji.1.2023.11.09.05.53.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 05:53:20 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 2/5] libsepol: set number of target names Date: Thu, 9 Nov 2023 14:53:12 +0100 Message-ID: <20231109135315.44095-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109135315.44095-1-cgzones@googlemail.com> References: <20231109135315.44095-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Set the number of target names to 0 instead of leaving it uninitialized. The number is always 0 since CIL does not support non-trivial not-self neverallow rules yet. Reported by Clang Analyzer: module_to_cil.c:1211:18: warning: The right operand of '<' is a garbage value [core.UndefinedBinaryOperatorResult] 1211 | for (t = 0; t < num_tnames; t++) { | ^ ~~~~~~~~~~ Signed-off-by: Christian Göttsche --- libsepol/src/module_to_cil.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c index d2868019..2d77e22a 100644 --- a/libsepol/src/module_to_cil.c +++ b/libsepol/src/module_to_cil.c @@ -1199,6 +1199,8 @@ static int avrule_list_to_cil(int indent, struct policydb *pdb, struct avrule *a rc = -1; goto exit; } + + num_tnames = 0; } else { ts = &avrule->ttypes; rc = process_typeset(pdb, ts, attr_list, &tnames, &num_tnames); From patchwork Thu Nov 9 13:53:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13451114 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 EF889C4167B for ; Thu, 9 Nov 2023 13:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234073AbjKINxZ (ORCPT ); Thu, 9 Nov 2023 08:53:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbjKINxY (ORCPT ); Thu, 9 Nov 2023 08:53:24 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C91F272C for ; Thu, 9 Nov 2023 05:53:22 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9a6190af24aso153072966b.0 for ; Thu, 09 Nov 2023 05:53:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1699538001; x=1700142801; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=0KItzZLwFEZg974XNkkFFeNNdCYF1cbO13DcgIokm1s=; b=THLXDRE3bmQOcMu4tp6o+Lfk8W/eKnHuurC63c6Q1BleVqkAwZ7achZdJOBumWwpun biYXV9TpwsGy3PyYR//vxQAPMhLcKJtF/axvOr78AAJI+V0XcYJ26AvEv8ojuZFoUdTl ns8487J30zQ+eaG4ox6C+MlWvYyR0H4yoqXyeigvGDHc74C9Arj6e+6cx/Tg62YMxjmL UI73/KSn/SV5QWW1I+ezzz9phuyAyb3myEWER7suuNVccQ/jZmbIKeeUiWroVMFJhrJu sKQG9G86cnmFo4zcm6zVlC+NK5vrNonUdDdzWbi1D65rN6xMf6ywLYi/ovHCRN4FaLip xKTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699538001; x=1700142801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0KItzZLwFEZg974XNkkFFeNNdCYF1cbO13DcgIokm1s=; b=H1UEeYUxrTSzrKkO4zEPNSrhhGYZ/E3gFRBMbQqvbUCr4VOuhABiAWlKABCkC47D5K HsdUrVDh1N4z6PiT0P4QV4BO8eKH7RSfc1A3si1VjU5+2GcRPltfCAkE1wKSYAON0NvZ a49/E/Y2KqdklQEeh4ljSCS6iIK6oLEezpU0uZqB48PicumgCdD90IvinEexxF/7wqFy 5HQkzJw4SQ63iXe/cpSjcOP/y8LbxE4PJMnFjRa3JhIyONw55DyazB/8jpcqRfcvCQwj RAMvfI9KEsJB9QI4Gbf+1eB4jH9EMqA3Q6MyBCJUTCYAN/Ck9TONu6HT+1SVNpjXjN94 BrFA== X-Gm-Message-State: AOJu0YyLNwNwx6qwX0NBVujtO91plqcj8MOwUwrukJ95Nrhtamxh2Csj lIf4woFpjRxwdqia1ih1iihzxaNlSxI= X-Google-Smtp-Source: AGHT+IFAxEquwgv5bDIj+AKd7xukG4et7jPsmrmCigokKQMsSxpZp2++3DGhogBkT4ybdDP7dP5i0w== X-Received: by 2002:a17:906:fd85:b0:9c7:5a14:ecf2 with SMTP id xa5-20020a170906fd8500b009c75a14ecf2mr4339189ejb.56.1699538000852; Thu, 09 Nov 2023 05:53:20 -0800 (PST) Received: from debian_development.DebianHome (dynamic-077-000-043-071.77.0.pool.telefonica.de. [77.0.43.71]) by smtp.gmail.com with ESMTPSA id q8-20020a1709060e4800b009de61c89f6fsm2549900eji.1.2023.11.09.05.53.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 05:53:20 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 3/5] libselinux: fix memory leak in customizable_init() Date: Thu, 9 Nov 2023 14:53:13 +0100 Message-ID: <20231109135315.44095-3-cgzones@googlemail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109135315.44095-1-cgzones@googlemail.com> References: <20231109135315.44095-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Reported by Clang Analyzer: is_customizable_type.c:36:3: warning: Potential leak of memory pointed to by 'buf' [unix.Malloc] 36 | fclose(fp); | ^~~~~~ Fixes: 9911f2ac6f77 ("libselinux: check for stream rewind failures") Signed-off-by: Christian Göttsche --- libselinux/src/is_customizable_type.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libselinux/src/is_customizable_type.c b/libselinux/src/is_customizable_type.c index 9be50174..da301c60 100644 --- a/libselinux/src/is_customizable_type.c +++ b/libselinux/src/is_customizable_type.c @@ -33,6 +33,7 @@ static void customizable_init(void) } if (fseek(fp, 0L, SEEK_SET) == -1) { + free(buf); fclose(fp); return; } From patchwork Thu Nov 9 13:53:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13451113 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 C744CC0018C for ; Thu, 9 Nov 2023 13:53:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbjKINxZ (ORCPT ); Thu, 9 Nov 2023 08:53:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232167AbjKINxZ (ORCPT ); Thu, 9 Nov 2023 08:53:25 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C37D2D5B for ; Thu, 9 Nov 2023 05:53:23 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9c773ac9b15so141257666b.2 for ; Thu, 09 Nov 2023 05:53:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1699538001; x=1700142801; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=LOrC+TCRJqtUUzRkJjSAHbz8Wj/EWYo6hIJbszfLzFE=; b=MtswKDIVZaTM2C++vQ/Ji+xfY+Jj1p6nIHumQhcyp8schzTogNnMM9wQHeZQVFhmjC XIbKm0kFenRigjcJ0R4mYEi//8O0GFQsMLttXlINKN553ABB78ZePUMdUl528pLf5316 MT0nQHBVfJiYLosI3OCEZ2vxrmwsBaDN2zeW+g0xbt7WPAPJgulNALXvpKnEipMXN2UN XxmM1TzPu86SIehsiRgIZzyb5K8IBtFqI8faWCKGdNA4ZA+emUTEAcE3UFByiI3al047 LXMWilotv47fdEQFzhE6qEN6fJZbOnH0vX1+N/UaKha8LRjqZSe2u7mphpWF+QXFGSIA avtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699538001; x=1700142801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LOrC+TCRJqtUUzRkJjSAHbz8Wj/EWYo6hIJbszfLzFE=; b=YGy0bayKvkDb321vu0Ok+xmKhojYdsQvYzAh6OvMOZRLI3cIywH3SJwqaNr9Qe4jZL S7w/vEXg/ATLd4kM6XMysoflzqygpACKy5pUnTGniemO+CWs2TF7IjyMnopNzDLM83aN XJt/7CzZ3ZjefoSrmRppjwkkvf4hxj8PvaXc451CGHeSF2Gr+cwcClVUWe3xqxWVnion oxuxrSep3RRAwwKXKMFgzcPB+SUCJjAwKrXCKRLgbhjoBbEjVXfvX1w63iPiP3IaxxbA OFSzwS7uHMUpg80yDRL7W0bTRBSA9OKBQpilMK0qdQnwDkGbBijobAw8TKqJVkTMNvuN vmJQ== X-Gm-Message-State: AOJu0Yyg6P2djwSdYWxlHNvLpRgRQ14vf8NK+MXBlklNPFmc8kbd1FmZ TMbcVXSOIwfNy6prEI+GxwFAGv5cHbA= X-Google-Smtp-Source: AGHT+IFFTyNMZlLtnu64ovySUZZGh67RhtnEy9S0AKCm5Ob71TgSPpmvB2IRST8+d+W5e2rEdACwXQ== X-Received: by 2002:a17:907:d89:b0:9bf:2673:7371 with SMTP id go9-20020a1709070d8900b009bf26737371mr4859038ejc.13.1699538001329; Thu, 09 Nov 2023 05:53:21 -0800 (PST) Received: from debian_development.DebianHome (dynamic-077-000-043-071.77.0.pool.telefonica.de. [77.0.43.71]) by smtp.gmail.com with ESMTPSA id q8-20020a1709060e4800b009de61c89f6fsm2549900eji.1.2023.11.09.05.53.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 05:53:21 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 4/5] libsepol: avoid leak in OOM branch Date: Thu, 9 Nov 2023 14:53:14 +0100 Message-ID: <20231109135315.44095-4-cgzones@googlemail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109135315.44095-1-cgzones@googlemail.com> References: <20231109135315.44095-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org In case the member sid_key failed to allocate, free the parent struct. Reported by Clang Analyzer: module_to_cil.c:2607:9: warning: Potential leak of memory pointed to by 'item' [unix.Malloc] 2607 | return rc; | ^~ Signed-off-by: Christian Göttsche --- libsepol/src/module_to_cil.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c index 2d77e22a..ee22dbbd 100644 --- a/libsepol/src/module_to_cil.c +++ b/libsepol/src/module_to_cil.c @@ -2582,6 +2582,7 @@ static int ocontext_isid_to_cil(struct policydb *pdb, const char *const *sid_to_ item->sid_key = strdup(sid); if (!item->sid_key) { ERR(NULL, "Out of memory"); + free(item); rc = -1; goto exit; } From patchwork Thu Nov 9 13:53:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13451115 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 898F0C4332F for ; Thu, 9 Nov 2023 13:53:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234238AbjKINx0 (ORCPT ); Thu, 9 Nov 2023 08:53:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbjKINxZ (ORCPT ); Thu, 9 Nov 2023 08:53:25 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C93E272C for ; Thu, 9 Nov 2023 05:53:23 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9c603e235d1so142844966b.3 for ; Thu, 09 Nov 2023 05:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1699538002; x=1700142802; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eV/5zBGqI9wBbtRO3IkTlt9j9AqN38cNWSn30T5kJhg=; b=hWILlDbbIOYSeXSWrjEqkR2XRT4QthnIXhrW9ja8j8kS4ArVlezBdTQINHlHIGdoJp +MYJURpKEx/UIptf3ISu8ARrl5pOMn5qjPsN5Ym7Fe7NLjxBqSWpeW3eOWX5NWFehtBt A7U/izeXbinEYm6gpWkluaeyVgADRGAoach3kNxEjPGc7sg9b/MKvzo/R8PzstI9gIq/ yQy6vSFGrOoASaZkSRtsio/Q8Dd/BHnq99/1szyNlZg4t+o9dmw3kgDWRRPy/XMJ8pe5 lGuWWUyIyGMz+eYZMdN6AmHA65lqHgNiCY7rkr3wSTExwdIV0Z4bu8zBglC3EiX9ojB2 wumA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699538002; x=1700142802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eV/5zBGqI9wBbtRO3IkTlt9j9AqN38cNWSn30T5kJhg=; b=a36BSpViLeab9O24eVuQQ2JtL67Vx59gODMX1SAjGy2jF0ksZm4lrmmMxt+53YRgav WOXl3/58x6K9eq3T38tXWcT4jEIWThsWdCd8+sqzvfH69wIB10568steBEQ+63X+nE/u b4OeckZJGh6QKr6FY2akZLLqlVGynIayHYxLp3BYKkVSLU/vv+7v/PLROXo2NFjF4KuE br6SPpoDsc7ZwAD8e3KyTmiwiDTcVsHAGUnnuZKDOJiEKQIwSx7+j+wrOTdQDGBppV5A QBfEdzSYEyrgzXbjN1I9vbUyyH8nH3qyrTytnHKH9wybzgcBX7HvIGEeJU+RmKAb2G/o eSHQ== X-Gm-Message-State: AOJu0YwzjWsApg4Rs+0QssxklakX5xTTymr0MCgYljvxs1OF5aC/WIjF uPHr5490+8LpEsNxn6bEd7D4Eu1ru8k= X-Google-Smtp-Source: AGHT+IFCbaiC0jC8Ls2li6AQ8omTujRM6LInDWGqhjhCtmoESg1aBLRmEUy90ODAAetAnr+S23Alug== X-Received: by 2002:a17:907:968c:b0:9c3:c2e1:a38e with SMTP id hd12-20020a170907968c00b009c3c2e1a38emr4486195ejc.15.1699538001868; Thu, 09 Nov 2023 05:53:21 -0800 (PST) Received: from debian_development.DebianHome (dynamic-077-000-043-071.77.0.pool.telefonica.de. [77.0.43.71]) by smtp.gmail.com with ESMTPSA id q8-20020a1709060e4800b009de61c89f6fsm2549900eji.1.2023.11.09.05.53.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 05:53:21 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 5/5] libsepol: avoid memory corruption on realloc failure Date: Thu, 9 Nov 2023 14:53:15 +0100 Message-ID: <20231109135315.44095-5-cgzones@googlemail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109135315.44095-1-cgzones@googlemail.com> References: <20231109135315.44095-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Use a single pointer variable for the realloc(3) result to not immediately override the source pointer. Also don't unnecessarily copy the first character. Reported by Clang Analyzer: services.c:810:14: warning: Assigned value is garbage or undefined [core.uninitialized.Assign] 810 | **r_buf = **new_buf; | ^ ~~~~~~~~~ Signed-off-by: Christian Göttsche --- libsepol/src/services.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libsepol/src/services.c b/libsepol/src/services.c index 51bd56a0..738a3404 100644 --- a/libsepol/src/services.c +++ b/libsepol/src/services.c @@ -787,8 +787,8 @@ mls_ops: if (r_buf && ((s[0] == 0) || ((s[0] == 1 && (flags & SHOW_GRANTED) == SHOW_GRANTED)))) { - int len, new_buf_len; - char *p, **new_buf = r_buf; + int len; + char *p; /* * These contain the constraint components that are added to the * callers reason buffer. @@ -801,13 +801,13 @@ mls_ops: len = snprintf(p, reason_buf_len - reason_buf_used, "%s", buffers[x]); if (len < 0 || len >= reason_buf_len - reason_buf_used) { - new_buf_len = reason_buf_len + REASON_BUF_SIZE; - *new_buf = realloc(*r_buf, new_buf_len); - if (!*new_buf) { + int new_buf_len = reason_buf_len + REASON_BUF_SIZE; + char *new_buf = realloc(*r_buf, new_buf_len); + if (!new_buf) { ERR(NULL, "failed to realloc reason buffer"); goto out1; } - **r_buf = **new_buf; + *r_buf = new_buf; reason_buf_len = new_buf_len; continue; } else {