From patchwork Wed Jan 8 16:31:49 2025 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: 13931319 X-Patchwork-Delegate: plautrba@redhat.com Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8C471FE457 for ; Wed, 8 Jan 2025 16:32:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736353924; cv=none; b=WYiPLL/6oHninwM6yKnq6dMg4Cdjmg5K1LQPFUX5GuKqBxmBGPyrUTdSGnuezr5BP/HUZeZ3jYSl4gXrOhG4WNgUjKU8zUclYTyynTZ+yM/VpwjcoM4Y4GHPuNX9XMQauCAXxL9Tu3Rcw/2MugJ0Xo56Ij5GQcxOban821fyOhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736353924; c=relaxed/simple; bh=P15Foa6JHzzaOFhVewob59AP8AxxKcDCKSpolOV0ScM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ME9t8VINi18Fr7NA2NtOJ4/5jjDB70HQVLZOaeLAtb0E/ks7giZTaOVRvWrZvzF0llImeKDF96YBXtBCcumCUfXsTA6/x7XjnbmNkGbnihzZMRVeCcsgiuypJape9GS8txeUgBSAXiCrmZ3lFHKHWlrgct1/kWIf42SnrxgKGx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=ugFZeIyt; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="ugFZeIyt" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1736353914; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VYapd+49nVDxjKqRC7Ig3ItyuHoI8pVvAG8U9IdoW8g=; b=ugFZeIytcTc7K6p5bP9GiL+YB+hGCkdAUZGA6cWxKXQ75P4X/SkWC6VN3XTP0QtNr2FN/y AMNxysnomY8H/C2iZKsFjs+RRMMUp7geM2i4ezz1ryeHG4SUxoAyFFO5HSElPvSq1Lzlwa Vk5BaYuaDVATnepRJR7TfxREafk9Gtlm8rB91CCLANNQEXnHTxlZe79kApcWS/fbPXHT22 rUL93Vy6baG/cUgyaKf05YwhkbzsLSESj7eRc1x0Wz4W8/JdzONl9PhvK74bME+dE4GtK6 se/MSmkU+U+4xlAnP4pQ2EHfE92qmlcVB1bSqc+FwcfwJ8OW7e0H0Ly9uDwqCA== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 1/2] libsepol/cil: free nlmsg hashtable on error Date: Wed, 8 Jan 2025 17:31:49 +0100 Message-ID: <20250108163149.104958-2-cgoettsche@seltendoof.de> In-Reply-To: <20250108163149.104958-1-cgoettsche@seltendoof.de> References: <20250108163149.104958-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche Free the hashtable for nlmsg xperm rules similar to the ioctl hashtable. Fixes: 1fd41f48 ("libsepol/cil: add support for xperms in conditional policies") Reported-by: oss-fuzz (issue 388376332) Signed-off-by: Christian Göttsche Acked-by: James Carter --- libsepol/cil/src/cil_binary.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsepol/cil/src/cil_binary.c b/libsepol/cil/src/cil_binary.c index 070bf525..e84188a0 100644 --- a/libsepol/cil/src/cil_binary.c +++ b/libsepol/cil/src/cil_binary.c @@ -2616,6 +2616,8 @@ int cil_booleanif_to_policydb(policydb_t *pdb, const struct cil_db *db, struct c return SEPOL_OK; exit: + hashtab_map(avrulex_nlmsg_table, __cil_avrulex_xperm_destroy, NULL); + hashtab_destroy(avrulex_nlmsg_table); hashtab_map(avrulex_ioctl_table, __cil_avrulex_xperm_destroy, NULL); hashtab_destroy(avrulex_ioctl_table); if (tmp_cond) { From patchwork Wed Jan 8 16:31:48 2025 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: 13931320 X-Patchwork-Delegate: plautrba@redhat.com Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8BED1F0E37 for ; Wed, 8 Jan 2025 16:32:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736353924; cv=none; b=JlMiTNysr9fO0m8FAGOgyHUChsvqKbcQxGPaZz04QqGiDFQNsncanXf/t1uVjgNgYHETgHOrb5jxjrSkNFCzvrIDSytTFADSj/7SpSrYBtPk/o7PfFwjq13NMVnFQBkqhToJPm/uY7AKDA6zWIu7F4rZu2eS7hu3BmhM3Kkdo40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736353924; c=relaxed/simple; bh=MszvDhfUkVuWixWeXzHMCC26KOY+6fTKeEh85HPdTyE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=T3/C9Gzkv79tZu0gDvcNZDyQ0PVxK89Sasu68ARN99TVsUY8VXZOBkjun4cjz53mBCjk8brsC13dnXecRDHwgP6Wi465Dp//ITTHmjba5oJrG5OwJFCnd5e0aRklOFuM/bcHJ7j6ySiG9JkTFznWl8AufwBZu5M5VkTKunCrRBk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=nhw3rWs8; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="nhw3rWs8" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1736353913; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kQp8TRoklno6SAEPb6jPy/JB0YjLjYDiSRZQduLFV98=; b=nhw3rWs8V0qY9TLODsci+Ucj40HMK7gZH69NPreg4HNhCPDoJSRpxlN1MIzal+VUgn5piw AJV2bhx+6Pa7iE9YbiTEJxVAjNTTKgpyiNOCnwnSc3/N3bWcO+YZ5ZrHMpOXQ9exKTuwPA hJobl3OHxK+vgrlbzwfHzgKiaJ3sqLz4sJUD4kyd86VDxzzQ1ap+hAwvuggVQjFFtfw5L4 iVL40XELq1xdT7ElbrScBc32PXwNxDuT0b8to57oFchCgNJjBM0fPpoP3TA58H6Uvr8aS/ hYuMRaVdipUlPL6nO/xiMMUsR7pc5k++riJxI4+2PHqLnGNsCjnxIqHoCxO9QA== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 2/2] libselinux/fuzz: handle inputs with trailing data Date: Wed, 8 Jan 2025 17:31:48 +0100 Message-ID: <20250108163149.104958-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche Handle the case where either separated trailing input is empty or non- existent by initializing the size to 0 and only call related code on non-zero size. Fixes: 8997f543 ("libselinux: add selabel_file(5) fuzzer") Reported-by: oss-fuzz (issue 388319478) Signed-off-by: Christian Göttsche --- .../fuzz/selabel_file_compiled-fuzzer.c | 67 ++++++++++++------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/libselinux/fuzz/selabel_file_compiled-fuzzer.c b/libselinux/fuzz/selabel_file_compiled-fuzzer.c index 09fbddd1..51fffcda 100644 --- a/libselinux/fuzz/selabel_file_compiled-fuzzer.c +++ b/libselinux/fuzz/selabel_file_compiled-fuzzer.c @@ -95,7 +95,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) uint8_t control; uint8_t *fcontext_data1 = NULL, *fcontext_data2 = NULL, *fcontext_data3 = NULL; char *key = NULL; - size_t fcontext_data1_len, fcontext_data2_len, fcontext_data3_len, key_len; + size_t fcontext_data1_len, fcontext_data2_len = 0, fcontext_data3_len = 0, key_len; bool partial, find_all; mode_t mode; int rc; @@ -141,11 +141,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) sep = memmem(data, size, separator, 4); if (sep) { fcontext_data2_len = sep - data; - fcontext_data2 = malloc(fcontext_data2_len); - if (!fcontext_data2) - goto cleanup; + if (fcontext_data2_len) { + fcontext_data2 = malloc(fcontext_data2_len); + if (!fcontext_data2) + goto cleanup; + + memcpy(fcontext_data2, data, fcontext_data2_len); + } - memcpy(fcontext_data2, data, fcontext_data2_len); data += fcontext_data2_len + 4; size -= fcontext_data2_len + 4; } @@ -153,11 +156,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) sep = memmem(data, size, separator, 4); if (sep) { fcontext_data3_len = sep - data; - fcontext_data3 = malloc(fcontext_data3_len); - if (!fcontext_data3) - goto cleanup; + if (fcontext_data3_len) { + fcontext_data3 = malloc(fcontext_data3_len); + if (!fcontext_data3) + goto cleanup; + + memcpy(fcontext_data3, data, fcontext_data3_len); + } - memcpy(fcontext_data3, data, fcontext_data3_len); data += fcontext_data3_len + 4; size -= fcontext_data3_len + 4; } @@ -202,29 +208,38 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) } fclose(fp); + fp = NULL; - fp = convert_data(fcontext_data2, fcontext_data2_len); - if (!fp) - goto cleanup; + if (fcontext_data2_len) { + fp = convert_data(fcontext_data2, fcontext_data2_len); + if (!fp) + goto cleanup; - errno = 0; - rc = load_mmap(fp, fcontext_data2_len, &rec, MEMFD_FILE_NAME, 1); - if (rc) { - assert(errno != 0); - goto cleanup; + errno = 0; + rc = load_mmap(fp, fcontext_data2_len, &rec, MEMFD_FILE_NAME, 1); + if (rc) { + assert(errno != 0); + goto cleanup; + } + + fclose(fp); + fp = NULL; } - fclose(fp); + if (fcontext_data3_len) { + fp = convert_data(fcontext_data3, fcontext_data3_len); + if (!fp) + goto cleanup; - fp = convert_data(fcontext_data3, fcontext_data3_len); - if (!fp) - goto cleanup; + errno = 0; + rc = load_mmap(fp, fcontext_data3_len, &rec, MEMFD_FILE_NAME, 2); + if (rc) { + assert(errno != 0); + goto cleanup; + } - errno = 0; - rc = load_mmap(fp, fcontext_data3_len, &rec, MEMFD_FILE_NAME, 2); - if (rc) { - assert(errno != 0); - goto cleanup; + fclose(fp); + fp = NULL; } sort_specs(&sdata);