From b6f173c5582a4d8f55b00b17d3cdb91fff809e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Date: Thu, 27 Jan 2022 11:36:16 +1100 Subject: [PATCH] Skip closef for property backend In 50400d3 the selabel_open function was updated to call selabel_close should the initialization of a backend fails. selabel_close includes a call to the backend-specific close function: closef. This same function is previously call, in case of an error, within the init function. The file backend was adapted by introducing a safe guard to prevent a double free. Update the property backend in a similar fashion. Bug: 215387420 Test: build & boot Change-Id: Id6b7c4d10538ccbec43b2af1de462da077f10c44 (cherry picked from commit 98fa1b865d52d97c06b754d1c2cfb69315997b65) Merged-In:Id6b7c4d10538ccbec43b2af1de462da077f10c44 --- libselinux/src/label_backends_android.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libselinux/src/label_backends_android.c b/libselinux/src/label_backends_android.c index d81faabe9..121b52f5d 100644 --- a/libselinux/src/label_backends_android.c +++ b/libselinux/src/label_backends_android.c @@ -278,6 +278,12 @@ static void closef(struct selabel_handle *rec) struct spec *spec; unsigned int i; + if (!data) + return; + + /* make sure successive ->func_close() calls are harmless */ + rec->data = NULL; + if (data->spec_arr) { for (i = 0; i < data->nspec; i++) { spec = &data->spec_arr[i];