SELinux: Fix memory leak upon loading policy

commit 8ed814602876bec9bad2649ca17f34b499357a1c upstream.

Hello.

I got below leak with linux-3.10.0-54.0.1.el7.x86_64 .

[  681.903890] kmemleak: 5538 new suspected memory leaks (see /sys/kernel/debug/kmemleak)

Below is a patch, but I don't know whether we need special handing for undoing
ebitmap_set_bit() call.
----------
>>From fe97527a90fe95e2239dfbaa7558f0ed559c0992 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Mon, 6 Jan 2014 16:30:21 +0900
Subject: SELinux: Fix memory leak upon loading policy

Commit 2463c26d "SELinux: put name based create rules in a hashtable" did not
check return value from hashtab_insert() in filename_trans_read(). It leaks
memory if hashtab_insert() returns error.

  unreferenced object 0xffff88005c9160d0 (size 8):
    comm "systemd", pid 1, jiffies 4294688674 (age 235.265s)
    hex dump (first 8 bytes):
      57 0b 00 00 6b 6b 6b a5                          W...kkk.
    backtrace:
      [<ffffffff816604ae>] kmemleak_alloc+0x4e/0xb0
      [<ffffffff811cba5e>] kmem_cache_alloc_trace+0x12e/0x360
      [<ffffffff812aec5d>] policydb_read+0xd1d/0xf70
      [<ffffffff812b345c>] security_load_policy+0x6c/0x500
      [<ffffffff812a623c>] sel_write_load+0xac/0x750
      [<ffffffff811eb680>] vfs_write+0xc0/0x1f0
      [<ffffffff811ec08c>] SyS_write+0x4c/0xa0
      [<ffffffff81690419>] system_call_fastpath+0x16/0x1b
      [<ffffffffffffffff>] 0xffffffffffffffff

However, we should not return EEXIST error to the caller, or the systemd will
show below message and the boot sequence freezes.

  systemd[1]: Failed to load SELinux policy. Freezing.

Change-Id: Id6c9bf7dc7df514f141ecf1d9c4c17be2c0ac2c8
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Eric Paris <eparis@redhat.com>
Signed-off-by: Paul Moore <pmoore@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
selinux: add a ugly workaround to bail early when selinux tries to free a socket that is still in use and it ends in a Kernel panic. These lines are from opensource.samsung.com. While this will most likely put a bandaid over this Kernel panic it does not fix the bug so it might occur somewhere else if the same conditions are met but since I have only seen panics from this hook then we may as well sleep in peace.

Change-Id: I5137878d98db001dd716bf642d48c4bae38dcd7f
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
LCD_KCAL: Color Control driver for OnePlus One

Change-Id: I6adb94c00ae689236a618cca73fbe3dec80a3c7f
LCD_KCAL: Introduce configurable kcal_min
Lower values such as 0-10 ultimately create a dark, washed out display,
if a user accidently sets their kcal values to "0 0 0" they will loose
visual control of the device, potentially requiring a hard reboot.
Introduce minimum kcal values to prevent this behavior.

Willing users can disable this protection by setting the kcal_min value
to '0', however the default value of 35 is recommended.

sysfs:
echo "1/255" > /sys/devices/platform/kcal_ctrl.0/kcal_min

kcal_min will detect and block values attempting to set lower than
itself, resetting the specific values to that of kcal_min. There is also
behavior to adjust the kcal if kcal_min is set to a level higher than
that of any kcal value(s).

Change-Id: I4c1bba5f157560d2f160b7667d3618e87b5c2131
LCD_KCAL: Prevent out-of-range input values

Change-Id: I25be4b6e678ef9a4be17b4a30f5f30bdb99c7c59
kcal: remove control bit, update lut every overlay start and clean some code.

Change-Id: I815d46e54ebeea6d8310f028d5dd89fc0f574f5a
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
board: kcal: add init values or the display boots completely black.

Change-Id: I4139ca1112b0830f6f02205c23e689b623d08c36
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
mdss: overlay: bye logs, was (not) nice to meet you.

Change-Id: I74c085af303d963db8bca05d1bd89eab6d81afe9
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Defconfig: Enable CONFIG_LCD_KCAL
LCD_KCAL: Fix compile with disabled CONFIG_LCD_KCAL

Change-Id: I74d765b17f35ab7fa8e8199a1b22e5e835303e91