udev: change security label 48/164248/2 accepted/tizen/unified/20171221.071349 submit/tizen/20171220.125854 submit/tizen/20171221.025332
authorSegwon <segwon.han@samsung.com>
Mon, 18 Dec 2017 07:58:17 +0000 (16:58 +0900)
committerSegwon <segwon.han@samsung.com>
Mon, 18 Dec 2017 08:16:13 +0000 (17:16 +0900)
 - when receiving fd to lib from daemon, the kernel blocks fd by security check.
 - change 90-gpio.rules name to 90-peripheral-io.rules

Change-Id: I5c75056e4d54fb667e6acdc7398f5f35ae9a3ff3
Signed-off-by: Segwon <segwon.han@samsung.com>
packaging/90-gpio.rules [deleted file]
packaging/90-peripheral-io.rules [new file with mode: 0644]
packaging/peripheral-bus.spec
src/gdbus/peripheral_gdbus_gpio.c
src/interface/peripheral_interface_pwm.c

diff --git a/packaging/90-gpio.rules b/packaging/90-gpio.rules
deleted file mode 100644 (file)
index a1dcd59..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
- RUN+="/bin/chown root:system_fw /sys%p/value",\
- RUN+="/bin/chmod g+rw /sys%p/value",\
- RUN+="/bin/chsmack -a System /sys%p/value"
-SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
- RUN+="/bin/chown root:system_fw /sys%p/direction",\
- RUN+="/bin/chmod g+rw /sys%p/direction",\
- RUN+="/bin/chsmack -a System /sys%p/direction"
-SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
- RUN+="/bin/chown root:system_fw /sys%p/edge",\
- RUN+="/bin/chmod g+rw /sys%p/edge",\
- RUN+="/bin/chsmack -a System /sys%p/edge"
diff --git a/packaging/90-peripheral-io.rules b/packaging/90-peripheral-io.rules
new file mode 100644 (file)
index 0000000..ca910bd
--- /dev/null
@@ -0,0 +1,18 @@
+SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
+ RUN+="/bin/chown root:root /sys%p/value",\
+ RUN+="/bin/chmod 0660 /sys%p/value",\
+ RUN+="/bin/chsmack -a * /sys%p/value"
+SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
+ RUN+="/bin/chown root:root /sys%p/direction",\
+ RUN+="/bin/chmod 0660 /sys%p/direction",\
+ RUN+="/bin/chsmack -a * /sys%p/direction"
+SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
+ RUN+="/bin/chown root:root /sys%p/edge",\
+ RUN+="/bin/chmod 0660 /sys%p/edge",\
+ RUN+="/bin/chsmack -a * /sys%p/edge"
+
+SUBSYSTEM=="i2c-dev", KERNEL=="i2c-*", ACTION=="add", \
+ MODE="0660", OWNER="root", GROUP="root", SECLABEL{smack}="*"
+
+SUBSYSTEM=="spidev", KERNEL=="spidev*.*", ACTION=="add", \
+ MODE="0660", OWNER="root", GROUP="root", SECLABEL{smack}="*"
index 0582b693785ae425b29cd9a68efee7a22a108a2f..214424a9be47600d3770c006ac0eae0fedfb9b8f 100644 (file)
@@ -8,7 +8,7 @@ Source0:    %{name}-%{version}.tar.gz
 Source1:    %{name}.manifest
 Source2:    %{name}.service
 Source3:    %{name}.tmpfiles.conf
-Source4:    90-gpio.rules
+Source4:    90-peripheral-io.rules
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(gio-2.0)
@@ -58,6 +58,6 @@ cp %{_builddir}/%{name}-%{version}/data/*.ini %{buildroot}/etc/%{name}
 %{_bindir}/%{name}
 %{_unitdir}/%{name}.service
 %{_tmpfilesdir}/%{name}.conf
-/usr/lib/udev/rules.d/90-gpio.rules
+/usr/lib/udev/rules.d/90-peripheral-io.rules
 %{_unitdir}/multi-user.target.wants/%{name}.service
 /etc/peripheral-bus/*.ini
index 20ca715fb624bfecb08ac5ec50f40bf3a64b5f06..6c0fe498adf78a9e23878eff40a79c9c10a8ea8c 100644 (file)
@@ -65,23 +65,24 @@ gboolean peripheral_gdbus_gpio_open(
                goto out;
        }
 
-       ret = peripheral_interface_gpio_export(pin);
+       ret = peripheral_handle_gpio_create(pin, &gpio_handle, user_data);
        if (ret != PERIPHERAL_ERROR_NONE) {
-               _E("Failed to export gpio");
+               _E("Failed to create gpio handle");
                goto out;
        }
 
-       ret = peripheral_interface_gpio_fd_list_create(pin, &gpio_fd_list);
+       ret = peripheral_interface_gpio_export(pin);
        if (ret != PERIPHERAL_ERROR_NONE) {
-               _E("Failed to create gpio fd list");
-               peripheral_interface_gpio_unexport(pin);
+               _E("Failed to export gpio");
+               peripheral_handle_gpio_destroy(gpio_handle);
                goto out;
        }
 
-       ret = peripheral_handle_gpio_create(pin, &gpio_handle, user_data);
+       ret = peripheral_interface_gpio_fd_list_create(pin, &gpio_fd_list);
        if (ret != PERIPHERAL_ERROR_NONE) {
-               _E("Failed to create gpio handle");
+               _E("Failed to create gpio fd list");
                peripheral_interface_gpio_unexport(pin);
+               peripheral_handle_gpio_destroy(gpio_handle);
                goto out;
        }
 
index d43f4a63eb9f973b36f5453f19573f6381a97156..c7c5c9552c581ceb0fde6b56677b8c866b5e579f 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <stdlib.h>
 #include "peripheral_interface_pwm.h"
 #include "peripheral_interface_common.h"
 
@@ -39,6 +40,34 @@ int peripheral_interface_pwm_export(int chip, int pin)
        ret = close(fd);
        IF_ERROR_RETURN(ret != 0);
 
+       snprintf(buf, MAX_BUF_LEN, "chsmack -a \"*\" /sys/class/pwm/pwmchip%d/pwm%d/period", chip, pin);
+       ret = system(buf);
+       if (ret != 0) {
+               _E("Failed to change period security label to read/write.");
+               return PERIPHERAL_ERROR_IO_ERROR;
+       }
+
+       snprintf(buf, MAX_BUF_LEN, "chsmack -a \"*\" /sys/class/pwm/pwmchip%d/pwm%d/duty_cycle", chip, pin);
+       ret = system(buf);
+       if (ret != 0) {
+               _E("Failed to change duty_cycle security label to read/write.");
+               return PERIPHERAL_ERROR_IO_ERROR;
+       }
+
+       snprintf(buf, MAX_BUF_LEN, "chsmack -a \"*\" /sys/class/pwm/pwmchip%d/pwm%d/polarity", chip, pin);
+       ret = system(buf);
+       if (ret != 0) {
+               _E("Failed to change polarity security label to read/write.");
+               return PERIPHERAL_ERROR_IO_ERROR;
+       }
+
+       snprintf(buf, MAX_BUF_LEN, "chsmack -a \"*\" /sys/class/pwm/pwmchip%d/pwm%d/enable", chip, pin);
+       ret = system(buf);
+       if (ret != 0) {
+               _E("Failed to change enable security label to read/write.");
+               return PERIPHERAL_ERROR_IO_ERROR;
+       }
+
        return PERIPHERAL_ERROR_NONE;
 }
 
@@ -53,8 +82,6 @@ int peripheral_interface_pwm_unexport(int chip, int pin)
        char path[MAX_BUF_LEN] = {0};
        char buf[MAX_BUF_LEN] = {0};
 
-       _D("chip : %d, pin : %d", chip, pin);
-
        snprintf(path, MAX_BUF_LEN, "/sys/class/pwm/pwmchip%d/unexport", chip);
        fd = open(path, O_WRONLY);
        IF_ERROR_RETURN(fd < 0);