platform/core/security/security-manager.git
15 months agoRelease 1.8.0 75/288675/1
Tomasz Swierczek [Tue, 21 Feb 2023 09:11:54 +0000 (10:11 +0100)]
Release 1.8.0

Package versioning bump to 1.8.X as Tizen 6.5 got update
(non-fast-forward) to 1.7.14.

This release is intended for tizen and tizen_7.0 branches.

Change-Id: I0c7fe641bb210c7ccfe5bf2e5db59f943083c9f4

16 months agoRelease 1.7.13 73/287673/1 accepted/tizen/7.0/unified/20230203.164158 accepted/tizen/unified/20230206.093841 accepted/tizen/unified/20230206.093957
Tomasz Swierczek [Thu, 2 Feb 2023 06:28:39 +0000 (07:28 +0100)]
Release 1.7.13

* Fix static analysis

Change-Id: I04137e1db4e557a6b4cdc828541773a2fad9b955

16 months agoFix static analysis 19/287319/4
Tomasz Swierczek [Thu, 26 Jan 2023 10:19:22 +0000 (11:19 +0100)]
Fix static analysis

Printing moved object is useless, even in debug logs.
The order of operation (logging vs moving) was changed.

Change-Id: I49ad49991e773ecf5ac65aa331b1cfb2bf1ad7cc

17 months agoRelease 1.7.12 28/285928/2 accepted/tizen/7.0/unified/20221223.170228 accepted/tizen/unified/20221226.020939
Tomasz Swierczek [Thu, 22 Dec 2022 10:30:01 +0000 (11:30 +0100)]
Release 1.7.12

* Change some logs into warnings

Change-Id: Ic77c3be5eb1b28648fecdce67ae14ebae9bac0d5

17 months agoChange some logs into warnings 25/285625/2
Tomasz Swierczek [Thu, 15 Dec 2022 11:54:50 +0000 (12:54 +0100)]
Change some logs into warnings

Per specific request of Visual Display Division.

Change-Id: I4e5f579dafa16aab7f7f443a9f57e15c443862b4

18 months agoRelease 1.7.11 30/284830/2 accepted/tizen/7.0/unified/20221129.084000 accepted/tizen/unified/20221129.172510
Tomasz Swierczek [Mon, 28 Nov 2022 11:13:28 +0000 (12:13 +0100)]
Release 1.7.11

* Add additional logs to security-manager

Change-Id: I430b7392a2176330b1fce3054a1ba1ca5ec49af6

18 months agoAdd additional logs to security-manager 29/284829/2
Tomasz Swierczek [Mon, 28 Nov 2022 11:11:50 +0000 (12:11 +0100)]
Add additional logs to security-manager

Per explicit request of Visual Display division.
One log changed to warning, also for specific request.

Change-Id: I6fbfc528002a78afd78e60699e342795248f4a1b

18 months agoRelease 1.7.10 50/284650/2 accepted/tizen/7.0/unified/20221124.171202 accepted/tizen/unified/20221124.015431
Tomasz Swierczek [Tue, 22 Nov 2022 09:53:19 +0000 (10:53 +0100)]
Release 1.7.10

* Disable LTO

Change-Id: If7bb805b212c5574a6cb501cb3893c2f037c9235

18 months agoDisable LTO 49/284649/2
Tomasz Swierczek [Tue, 22 Nov 2022 09:44:42 +0000 (10:44 +0100)]
Disable LTO

In case LTO is enabled, function defined in asm (and declared as such)
generates error at linking stage (client-security-manager.cpp, function
__restore_rt).

Change-Id: I31ff9de14755b9b531f25e777c439f7153c6548c

18 months agoRelease 1.7.9 52/284152/1 tizen_7.0_unified accepted/tizen/unified/20221118.021706
Tomasz Swierczek [Thu, 10 Nov 2022 14:31:26 +0000 (15:31 +0100)]
Release 1.7.9

* Change delay for setting cpu_inheritance

Change-Id: I5e362885ee4029b67062247011fd9d55a2942739

18 months agoChange delay for setting cpu_inheritance 51/284151/1
Tomasz Swierczek [Thu, 10 Nov 2022 14:31:08 +0000 (15:31 +0100)]
Change delay for setting cpu_inheritance

Change-Id: If46ba6429226c4fcd7a64179fb93d715c84f1635

19 months agoRelease 1.7.8 62/283062/2 accepted/tizen/unified/20221102.020605
Tomasz Swierczek [Mon, 17 Oct 2022 11:38:07 +0000 (13:38 +0200)]
Release 1.7.8

* Change logic of security_manager_app_update()

Change-Id: If230c9a5aa87b294066c830b9582b678c6e6ad1c

19 months agoChange logic of security_manager_app_update() 61/283061/2
Tomasz Swierczek [Mon, 17 Oct 2022 08:31:09 +0000 (10:31 +0200)]
Change logic of security_manager_app_update()

Now the function allows to update package & remove not-requested
appIds present before even if no hybrid status change has been done.

Change-Id: I3f13dddd726c57e6a1572ce3a608eaf16768ad55

21 months agoRelease 1.7.7 57/280957/1 accepted/tizen_7.0_unified_hotfix tizen_7.0_hotfix accepted/tizen/7.0/unified/20221110.061233 accepted/tizen/7.0/unified/hotfix/20221116.105634 accepted/tizen/unified/20220915.173202 accepted/tizen/unified/20220916.022052 accepted/tizen/unified/20220916.022130 tizen_7.0_m2_release
Tomasz Swierczek [Wed, 7 Sep 2022 06:33:51 +0000 (08:33 +0200)]
Release 1.7.7

* Appease SVACE

Change-Id: If5cdbb74949e2728859bbdb73be17a6626f05b4d

21 months agoAppease SVACE 58/280158/1
Konrad Lipinski [Wed, 24 Aug 2022 12:07:36 +0000 (14:07 +0200)]
Appease SVACE

Change-Id: I9da1046731377e5c47096f34769f38aa67a23ae2

21 months agoRelease 1.7.6 55/279555/2 accepted/tizen/unified/20220817.153738 submit/tizen/20220811.131445 submit/tizen/20220816.102758
Konrad Lipinski [Thu, 11 Aug 2022 10:49:58 +0000 (12:49 +0200)]
Release 1.7.6

* Fix out of bounds socket description vector access
* Delay service thread construction until dependencies are initialized
* Decrease message buffer test payload size to avoid bad_alloc
* Refactor errno logging

Change-Id: I8287171336f96d277ea7608213cb5b26c5901dbb

21 months agoFix out of bounds socket description vector access 46/279546/1
Konrad Lipinski [Thu, 11 Aug 2022 08:50:44 +0000 (10:50 +0200)]
Fix out of bounds socket description vector access

Change-Id: Iacfa7ad31ad1aa5e7f4743fc114e283acc58af8e

21 months agoDelay service thread construction until dependencies are initialized 45/279545/1
Konrad Lipinski [Thu, 11 Aug 2022 08:30:16 +0000 (10:30 +0200)]
Delay service thread construction until dependencies are initialized

Change-Id: I386c56804eae770e0bb90acbecc705d14010d804

22 months agoDecrease message buffer test payload size to avoid bad_alloc 17/279517/1
Konrad Lipinski [Wed, 10 Aug 2022 15:23:54 +0000 (17:23 +0200)]
Decrease message buffer test payload size to avoid bad_alloc

Change-Id: I24c1b17e5b8e8d224b7c8d47dbe0942467e528bf

22 months agoRefactor errno logging 95/279395/3
Konrad Lipinski [Tue, 2 Aug 2022 13:33:07 +0000 (15:33 +0200)]
Refactor errno logging

* Macros to factor out common patterns.
* Minor error detection optimization at sites that happened to be nearby.

Change-Id: Ibd14776e5d52fa59c00098317bc8031fb351eb0b

22 months agoRelease 1.7.5 58/279258/1 accepted/tizen/unified/20220804.151648 accepted/tizen/unified/20220805.131919 submit/tizen/20220803.102654 submit/tizen/20220804.142848
Konrad Lipinski [Thu, 4 Aug 2022 14:07:37 +0000 (16:07 +0200)]
Release 1.7.5

* Add subsession bind mount isolation

Change-Id: Idee1eac89d529884900b97847b64ad239d4252b7

22 months agoAdd subsession bind mount isolation
Konrad Lipinski [Tue, 26 Jul 2022 10:52:49 +0000 (12:52 +0200)]
Add subsession bind mount isolation

By introducing prepare_app2(app_id, subsession_id) and implementing
prepare_app(app_id) as prepare_app2(app_id, nullptr). Null subsession_id
indicates the default subsession.

The selected subsession is mounted over the "apps_rw" directory. Other
subsessions are hidden by mounting an empty directory over the user's
"subsession" directory if it exists.

Change-Id: I19c884bdd64c53b82fef3447470378c8a8cfae3e

22 months agoRelease 1.7.4 04/279204/1
Konrad Lipinski [Wed, 3 Aug 2022 10:15:39 +0000 (12:15 +0200)]
Release 1.7.4

* Drop std::function from try_catch() and friends, deficient edition
* Simplify socket-manager timeout logic
* Switch to CLOCK_MONOTONIC_COARSE
* Refrain from calling sessiond in offline mode
* Prioritize requests based on cpu boosting level
* Simplify service and IO thread's class hierarchies
* Make socket manager counters more robust
* Refactor MessageBuffer and dependencies

Change-Id: Id35cf58156eef658907b312df06637e51ce5e9dd

22 months agoDrop std::function from try_catch() and friends, deficient edition 00/276900/2
Konrad Lipinski [Mon, 16 May 2022 17:39:29 +0000 (19:39 +0200)]
Drop std::function from try_catch() and friends, deficient edition

When used as an argument to try_catch() and similar functions,
std::function may potentially introduce runtime overhead on the
exception-free path, possibly even allocate (and thus throw
std::bad_alloc).

This can be prevented by rewriting try_catch() as a generic wrapper with
perfect forwarding.

This has been coded deficiently on purpose, refusing to leverage any and
all kinds of bloat reduction opportunities. For the rationale, please
consult code review participants as I have none to give.

  "I'm only following orders."
    - A nameless soldier

Change-Id: I00adf24213a2e6bf8d148db8375a14200c64ff4f

22 months agoSimplify socket-manager timeout logic 24/279124/3
Konrad Lipinski [Mon, 18 Jul 2022 08:14:44 +0000 (10:14 +0200)]
Simplify socket-manager timeout logic

The intention of the timeout logic is to close stale sockets (ones that
have been inactive for SOCKET_TIMEOUT seconds). The closure doesn't
really have to happen immediately after that, as long as it happens
eventually when, say, security-manager's IO thread wakes up.

* use select() without timeout
* replace timeout priority queue with generation-based management
* each generation lasts at least SOCKET_TIMEOUT seconds
* maintain per-socket activity booleans for the current generation
* a socket becomes active when performing or getting primed for IO
* when a new generation begins, loop through all sockets, time out all
  inactive ones, set all remaining to inactive

Change-Id: I50a06f1566806fa9d7d69fe2367d6ade0f93acf5

22 months agoSwitch to CLOCK_MONOTONIC_COARSE 23/279123/3
Konrad Lipinski [Tue, 2 Aug 2022 07:35:50 +0000 (09:35 +0200)]
Switch to CLOCK_MONOTONIC_COARSE

All uses of clock_gettime() are fine with coarse granularity. Renamed
monotonicNow() to monotonicCoarseNow() to reflect that.

Change-Id: Id60e79ca28a888ad98907184b7c11dd9d0b4aeee

22 months agoRefrain from calling sessiond in offline mode 34/278934/3
Konrad Lipinski [Thu, 28 Jul 2022 07:53:10 +0000 (09:53 +0200)]
Refrain from calling sessiond in offline mode

Change-Id: I0e182d45f75cc99cbc11d692c29e6c7c0bcc0719

22 months agoPrioritize requests based on cpu boosting level 09/277809/15
Konrad Lipinski [Wed, 13 Jul 2022 14:46:48 +0000 (16:46 +0200)]
Prioritize requests based on cpu boosting level

There are three boosting levels at present, hence three distinct
priorities are introduced. Since the priority space is small, the
priority queue is implemented via an array of FIFO queues.

CPU priority inheritance from client to server is also included.

The boosting level and priority inheritance facilities are provided by
the capi-system-resource module. According to said facilities'
designers, querying the boosting level is most efficient when done
directly in the queried thread. Thus, when making a security manager
client request, the boosting level is obtained and prepended to the
request payload. This is also makes requests atomic and mitigates the
potential for priority races.

Change-Id: Icc10fb5e40fa74eafe16726d28ac66cd8b560810

22 months agoSimplify service and IO thread's class hierarchies 51/278451/5
Konrad Lipinski [Wed, 20 Jul 2022 11:57:14 +0000 (13:57 +0200)]
Simplify service and IO thread's class hierarchies

* get rid of useless Generic* and Base* classes that do nothing
* shift what little functionality they provided to other entities
* make a few leaf classes final
* devirtualize a few methods across the hierarchy, either by making them
  local or via CRTP
* replace the virtual Event hierarchy and handlers by a single
  statically known Event type

Change-Id: Id3afef98ff99a5b0eb3966f1cfdf0dcaa52cd909

22 months agoMake socket manager counters more robust 05/277805/9
Konrad Lipinski [Wed, 13 Jul 2022 13:25:52 +0000 (15:25 +0200)]
Make socket manager counters more robust

Now that the service no longer needs to maintain a dictionary of all
socket connections, socket counters no longer need to be globally
unique. The only remaining use for those counters now involves checking
whether a particular socket descriptor has gone stale. Per-descriptor
counters are enough for that, incremented every time a particular
descriptor is reopened.

* use per-socket counters instead of a global one
* use unsigned for guaranteed wraparound
* increment counter when closing instead of when opening to make the
  check for isOpen unnecessary when checking connections enqueued in
  m_closeQueue or m_writeBufferQueue

Change-Id: I5b9102c6fe3f9eb183ce456d1334173ac37aab4b

22 months agoRefactor MessageBuffer and dependencies 03/277803/9
Konrad Lipinski [Tue, 12 Jul 2022 09:01:37 +0000 (11:01 +0200)]
Refactor MessageBuffer and dependencies

Security manager's protocol assumes there's at most one message in
flight per connection at any given time. The MessageBuffer class can
hold one such message in various stages of completion, assembled via
either input or serialization and disposed of via either output or
deserialization.

This conceptual interface can be satisfied in a much simpler way than
what's currently present. All that is require for a MessageBuffer is a
single contiguous memory block and a little management on the side
(the block's size, the message size, offset into the block).

Since the protocol has the payload size stored as a size_t header prior
to a message's payload, there's no need to even store it separately - it
can be stored before the payload, just as in the protocol.

Implications:
* less memory copying/shuffling
  * read the full message directly into a buffer in binary form
  * deserialize directly from that buffer (no Pop(), no copies)
  * reuse the buffer space for serialization of the return message
  * output the return message into the socket without copying
* socket manager now assembles full messages before handing them to the
  service, at no performance hit
* one MessageEvent per socket instead of Accept/Close/Read/Write events
* no need for the service to maintain connection state - it now operates
  on a per-message basis

Change-Id: I45f6009ce09ae2f852cfee86a32426389bcf7a30

22 months agoRelease 1.7.3 51/278351/1 accepted/tizen/unified/20220720.064051 submit/tizen/20220719.015501
Konrad Lipinski [Tue, 19 Jul 2022 10:56:07 +0000 (12:56 +0200)]
Release 1.7.3

* Decrease service thread lock thrashing
* Fix subsession paths

Change-Id: I5fafb902584edfb88b6566ace91126cbe44761fa

22 months agoDecrease service thread lock thrashing 07/277807/5
Konrad Lipinski [Wed, 13 Jul 2022 14:13:55 +0000 (16:13 +0200)]
Decrease service thread lock thrashing

By not releasing the lock right after wait() returns.

Change-Id: Ic689aed448b9a00370252be2b09d7cb653bdcdc5

22 months agoFix subsession paths 85/278285/3
Konrad Lipinski [Mon, 18 Jul 2022 10:22:49 +0000 (12:22 +0200)]
Fix subsession paths

* place the "subsession" dir in TZ_USER_HOME instead of TZ_USER_APP
* skip over the empty subsession as returned by sessiond
* add sharedRO paths if applicable
* refrain from labelling paths inside skelDir for local installations
* refactor related code to reduce redundancy and improve robustness

Change-Id: I2ede9f53f490c9bf57d390796e2ca5a1774f8a09

22 months agoRelease 1.7.2 58/277958/1 accepted/tizen/unified/20220718.140340 accepted/tizen/unified/20220719.014554 submit/sessiond/20220715.092836 submit/tizen/20220715.093042 submit/tizen/20220718.045828 submit/tizen/20220718.115742
Konrad Lipinski [Fri, 15 Jul 2022 08:41:01 +0000 (10:41 +0200)]
Release 1.7.2

* Basic integration with sessiond
* Drop socket manager multi service support
* Handle signals locally in socket manager main loop
* Switch socket manager notification from pipe to eventfd
* Remove unused sendmsg functionality

Change-Id: I9f21d9709dd6d0b7d8b2e446590d738d7f6d7504

22 months agoBasic integration with sessiond 87/277887/2
Tomasz Swierczek [Wed, 30 Mar 2022 11:40:54 +0000 (13:40 +0200)]
Basic integration with sessiond

Allow ~/subsession/$light_username/apps_rw/$pkgName as legal package
directories as needed by the lightweight multiuser feature.

New paths are in force ONLY for local app installation
(for SM_APP_INSTALL_LOCAL install type in security-manager's API).

Lacks bind-mounting per-user relevant datadirs (separation of user
data). This is supposed to be added at later stage.

Change-Id: Ia042e608781c139651578475c94d4283ddf70a47

22 months agoDrop socket manager multi service support 37/277737/3
Konrad Lipinski [Tue, 12 Jul 2022 14:01:11 +0000 (16:01 +0200)]
Drop socket manager multi service support

That feature has never been used, it's always been dead weight.
Security manager is a single service so that's unlikely to ever change.

Implications:
* no need to store/check interface ID
* one service per socket manager - less bookkeeping, simpler destructor
* socket descriptors now only apply to accepted sockets

Change-Id: I84ce915f0ff6929df45a40a0a8f5cbf7a4214694

22 months agoHandle signals locally in socket manager main loop 32/277732/1
Konrad Lipinski [Tue, 12 Jul 2022 11:36:59 +0000 (13:36 +0200)]
Handle signals locally in socket manager main loop

* replace SignalService with a local descriptor
* handle the descriptor directly in the main loop
* drop the now unused m_working and MainLoopStop()

White at it, also drop the harmful TEMP_FAILURE_RETRY when calling
close() on service sockets.

Change-Id: I172456d1762aaed4c4f0dd46a49732aa28d9c5d6

22 months agoSwitch socket manager notification from pipe to eventfd 23/277723/2
Konrad Lipinski [Tue, 12 Jul 2022 09:49:53 +0000 (11:49 +0200)]
Switch socket manager notification from pipe to eventfd

* use eventfd for a more efficient wakeup mechanism
* handle it directly in the manager thread to reduce thrashing
* drop the now useless DummyService and SIGPIPE-related code
* check m_working in the main loop only if eventfd is ready for reading

Change-Id: I090d90a50f3c789445dd6d0daa637abf0d189348

23 months agoRemove unused sendmsg functionality 90/277490/1
Krzysztof Jackiewicz [Thu, 7 Jul 2022 12:00:27 +0000 (14:00 +0200)]
Remove unused sendmsg functionality

Kind of reverts 0798413641b7961a0132050aef6bd03270936625

Change-Id: I815e63a370528762f69b760340398e068b541b74

2 years agoRelease 1.7.1 04/275204/1
Tomasz Swierczek [Wed, 18 May 2022 07:00:01 +0000 (09:00 +0200)]
Release 1.7.1

* Enhance DB recovery logic
* Minor fix of wording in comment
* Remove unused code

Change-Id: Ide32e4e3257810994bcb8dfe6695c455e5c0007f

2 years agoEnhance DB recovery logic 40/274440/3
Tomasz Swierczek [Thu, 28 Apr 2022 09:13:42 +0000 (11:13 +0200)]
Enhance DB recovery logic

"If we are wise, let us prepare for the worst."
- George Washington

Previously, the logic of DB recovery was:

1. Remove the "-recovered" file flag, IF it survived reboot (shouldn't)
2. Check DB for corruption
3. IF corruption occured, then:
   a. Replace original DB with fallback made at image creation
   b. Create the "-recovered" file next to DB file that signals rest of the system some apps may be missing

If sudden poweroff happens between 3a and 3b, system will not get informed
about missing app installation data.

This patch changes order of operations 3a and 3b, and also removes
operation number 1. From now on, the system-level scripts responsible
for recovery should remove the flag, when full recovery was complete.

Changing order of 3a with 3b ensures the flag is created when
DB error was found and is not prone to sudden power-off.

The flag is meant to be used for file-existance signalling of the need
to reinstall apps that were not in the backed-up DB. Since its existence
can trigger app installation, which in turn, can launch & use security-manager
(which will also attemt to access the DB), it MUST be ensured that rules-loader
is not running concurrently with any other processes/services that may use security-manager's DB
(the recovery of DB from fallback/backup has to be complete). This is achieved
by systemd's "Before=" service option in rules-loader service file which prohibits
security-manager's socket & service start before rules loader-ends operation.

Change-Id: I472c09d9398f69a97e118b69aad61dc016e3d22d

2 years agoMinor fix of wording in comment 49/274649/1
Tomasz Swierczek [Wed, 4 May 2022 06:42:32 +0000 (08:42 +0200)]
Minor fix of wording in comment

Change-Id: I48e795f72a7ca2ad720ea475c611d57d1007a622

2 years agoRemove unused code 88/273088/1
Tomasz Swierczek [Wed, 30 Mar 2022 11:10:38 +0000 (13:10 +0200)]
Remove unused code

Change-Id: I7ae95050e5018d3a38ee79401553b46e3dfc849b

2 years agoRelease 1.7.0 15/267515/1 accepted/tizen/unified/20211208.121745 submit/tizen/20211207.102655
Tomasz Swierczek [Mon, 6 Dec 2021 11:05:47 +0000 (12:05 +0100)]
Release 1.7.0

Bump versioning to 1.7.X as tizen_6.0 has branched-off.

This change should be synced to tizen_6.5 branch, too.

Change-Id: Ibed180c8cbc9df8d96b3e0bf0188b8c3d6d5bf9f

2 years agoRelease 1.6.21 81/265981/1 submit/tizen/20211103.072942
Tomasz Swierczek [Wed, 3 Nov 2021 06:45:41 +0000 (07:45 +0100)]
Release 1.6.21

* Retry blocking waitpid() on EINTR

Change-Id: I20c9a73a6e7573dddc8d4b3495e74031e620d036

2 years agoRetry blocking waitpid() on EINTR 44/265844/2
Konrad Lipinski [Fri, 29 Oct 2021 12:19:54 +0000 (14:19 +0200)]
Retry blocking waitpid() on EINTR

Change-Id: I0b7bcc0ce1964a229b77a8456266696f4ae0a80b

2 years agoRelease 1.6.20 27/263027/1 accepted/tizen/6.5/unified/20211028.121909 accepted/tizen/unified/20210830.103938 submit/tizen/20210826.015715 submit/tizen/20210827.231742 submit/tizen_6.5/20211028.162401 tizen_6.5.m2_release
Jin-gyu Kim [Wed, 25 Aug 2021 19:22:30 +0000 (04:22 +0900)]
Release 1.6.20

* Adding privilege group priv_platform.

Change-Id: If9dc65658e85143ef77cd0d117cc4fd22124215c

2 years agoAdding privilege group priv_platform. 89/262989/1
Jin-gyu Kim [Wed, 25 Aug 2021 02:25:22 +0000 (11:25 +0900)]
Adding privilege group priv_platform.

Adding group for http://tizen.org/privilege/internal/default/platform

Change-Id: Ib8c4d82e08b48d6cb233a626960806fe0f69c4ae

2 years agoRelease 1.6.19 38/260338/1 accepted/tizen/unified/20210624.131820 submit/tizen/20210624.042100
Jin-gyu Kim [Thu, 24 Jun 2021 04:05:55 +0000 (13:05 +0900)]
Release 1.6.19

* Adding privilege group priv_peripheralio
* Make prepare_app() safer in non-main threads

Change-Id: I8d25212ea1ae5042b0a894b172884b49ce38f3b7

2 years agoAdding privilege group priv_peripheralio. 31/260231/1
Jin-gyu Kim [Wed, 23 Jun 2021 02:01:00 +0000 (11:01 +0900)]
Adding privilege group priv_peripheralio.

Adding priv_peripheralio group for http://tizen.org/privilege/peripheralio

Change-Id: I2a8ef3344d4d4840b918f72a1a836bfc0be7a4ce

3 years agoMake prepare_app() safer in non-main threads 26/259426/1
Konrad Lipinski [Mon, 7 Jun 2021 16:44:55 +0000 (18:44 +0200)]
Make prepare_app() safer in non-main threads

Calling prepare_app() from a non-main thread in a multithreaded
process could fail. While labels for other threads were being correctly
set by writing to /proc/<tid>/attr/current, the prepare_app thread used
smack_set_label_for_self() and thus /proc/self/attr/current.

This is easily fixed by reusing label_for_self_internal() so that all
threads are uniformly treated, each using its own tid.

Change-Id: Id5b3071b08057200331d64bf8d6cd172ae729df1

3 years agoRelease 1.6.18 59/257059/2 accepted/tizen/unified/20210420.002102 submit/tizen/20210419.055111
Yunjin Lee [Mon, 19 Apr 2021 05:06:41 +0000 (14:06 +0900)]
Release 1.6.18

* Add core privileges: usb.host and log

Change-Id: Ic5ede43127e8c194943e18846b4ec10d4da220e9

3 years agoAdd core privileges: usb.host and log 72/256672/3
Yunjin Lee [Fri, 9 Apr 2021 04:29:36 +0000 (13:29 +0900)]
Add core privileges: usb.host and log

- usb.host: app can access to connected external USB devices
- log: app can access to platform log data
- both are platform level
- http://tizen.org/privilege/log is mapped to gid log
- http://tizen.org/privilege/usb.host is mapped to gid usb_device

Change-Id: I1726b463c077921071ff9b9f0348effe80ade38c
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
3 years agoRelease 1.6.17 70/256670/1 accepted/tizen/unified/20210412.012045 submit/tizen/20210409.020205
Yunjin Lee [Fri, 9 Apr 2021 01:42:50 +0000 (10:42 +0900)]
Release 1.6.17

* Fix issue from static analysis

Change-Id: I30597162967bc6bd2ee073030e4cd4cef82402b8

3 years agoFix issue from static analysis 53/256653/1
Tomasz Swierczek [Thu, 8 Apr 2021 12:39:19 +0000 (14:39 +0200)]
Fix issue from static analysis

The ChannelCreator::closeAll(), when called in copy constructor,
may operate on uninitialized data.

Change-Id: Iaec6b3edc7e685ce14f7ea8e4d94eb3f59c9f4b7

3 years agoRelease 1.6.16 20/255720/1 accepted/tizen/unified/20210325.122724 submit/tizen/20210323.045229 submit/tizen/20210324.085352
Yunjin Lee [Tue, 23 Mar 2021 03:07:07 +0000 (12:07 +0900)]
Release 1.6.16

* Add core privilege: bugreport.admin
* Fix coverage generation in rpm 4.14.1

Change-Id: I0886eb78e3f1fbdb94d48c20a62a9b4468af9560

3 years agoAdd core privilege: bugreport.admin 09/255709/1
Yunjin Lee [Tue, 23 Mar 2021 01:13:07 +0000 (10:13 +0900)]
Add core privilege: bugreport.admin

With http://tizen.org/privilege/bugreport.admin, app can request
creation of system or app's bugreport.

Change-Id: I4826ad7d7543d1945fae016f6f7146702287d6fc
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
3 years agoFix coverage generation in rpm 4.14.1 89/254489/1
Tomasz Swierczek [Wed, 3 Mar 2021 13:55:09 +0000 (14:55 +0100)]
Fix coverage generation in rpm 4.14.1

Debug source package directories now have different names.

Change-Id: Icffd332802d5d37d4d9d61fa96d75fdaad78a538

3 years agoRelease 1.6.15 82/253382/1 accepted/tizen/unified/20210210.130306 submit/tizen/20210209.105224
Tomasz Swierczek [Tue, 9 Feb 2021 10:21:58 +0000 (11:21 +0100)]
Release 1.6.15

* Change systemd-devel package name
* Drop http://tizen.org/privilege/internal/livecoredump mapping to priv_livecoredump

Change-Id: Ibcaf231abb98267472226761ef404da021eab000

3 years agoChange systemd-devel package name 98/252898/1
INSUN PYO [Wed, 3 Feb 2021 04:35:56 +0000 (13:35 +0900)]
Change systemd-devel package name

Change-Id: I25635d30ce598200c1e14cc0287ecd5da40c9eff

3 years agoDrop http://tizen.org/privilege/internal/livecoredump mapping to priv_livecoredump 11/252211/1
Karol Lewandowski [Mon, 25 Jan 2021 15:12:13 +0000 (16:12 +0100)]
Drop tizen.org/privilege/internal/livecoredump mapping to priv_livecoredump

The priv_livecoredump group was supposed to be used by system services
wanting to use livecoredump API. (For applications it's granted by app
manifest.)

Unfortunately, it's not allowed by tizen sanity checkers to specify priv_*
groups in dbus policy, which renders the mapping useless.  System services
must use other means to grant access to the API (as described in livecoredump
repository).

Change-Id: I58984358d095515a57d217ca277e3b06cda40703

3 years agoRelease 1.6.14 72/247372/1 accepted/tizen/6.0/unified/20201113.014504 submit/tizen/20201110.104055 submit/tizen_6.0/20201110.104618 submit/tizen_6.0/20201111.025917
Tomasz Swierczek [Tue, 10 Nov 2020 07:32:31 +0000 (08:32 +0100)]
Release 1.6.14

* Add Requires=local-fs.target dependency to security-manager-rules-loader.service
* Automate code coverage measurement

Change-Id: Ib6a86a3361b2eebb7e2ba121e54c558514b24a91

3 years agoAdd Requires=local-fs.target dependency to security-manager-rules-loader.service 15/245415/2
INSUN PYO [Thu, 8 Oct 2020 08:41:28 +0000 (17:41 +0900)]
Add Requires=local-fs.target dependency to security-manager-rules-loader.service

In emergency mode, local-fs.target always fails.
So, you have to check if local-fs.target is successful.

Change-Id: I4a946f573dd714f77b510ae818497c7d24ea4e4d

3 years agoAutomate code coverage measurement 89/242889/9
Dariusz Michaluk [Tue, 1 Sep 2020 12:33:41 +0000 (14:33 +0200)]
Automate code coverage measurement

To gather unit tests coverage report:
- use COVERAGE build_type,
- instal security-manager-coverage rpm,
- run security-manager-coverage.sh script.

Change-Id: I34960e55e4cff81d0e99864e3c3ed4d5d3c48385

3 years agoRelease 1.6.13 39/246439/1 submit/tizen/20201029.120735
Tomasz Swierczek [Thu, 29 Oct 2020 08:56:29 +0000 (09:56 +0100)]
Release 1.6.13

* Add check for $TZ_SYS_RUN/lock existance in update scripts

Change-Id: I57e51af38527cdac9b350bcf0561094744f83290

3 years agoAdd check for $TZ_SYS_RUN/lock existance in update scripts 38/246438/1
Tomasz Swierczek [Thu, 29 Oct 2020 08:55:09 +0000 (09:55 +0100)]
Add check for $TZ_SYS_RUN/lock existance in update scripts

The location for locking directory can be not mounted/not created
yet at update running time. TV images should not run security-manager
at this moment, so the updaring script should continue normally

Change-Id: I8d84af74a33354efd5e5dcae672340793d3d961d

3 years agoRelease 1.6.12 83/246183/4 accepted/tizen/unified/20201027.124944 submit/tizen/20201026.160418
Tomasz Swierczek [Mon, 26 Oct 2020 11:06:18 +0000 (12:06 +0100)]
Release 1.6.12

* Relax exit-on-error in update scripts
* Change FileLocker implemenation from POSIX to libc flocks

Change-Id: If53124c609da6f196feab8a3e9e68c46a2ea7714

3 years agoRelax exit-on-error in update scripts 82/246082/8
Tomasz Swierczek [Fri, 23 Oct 2020 06:54:16 +0000 (08:54 +0200)]
Relax exit-on-error in update scripts

These scripts use systemctl systemd command to start & stop service/socket
of security-manager. On systems where systemd is not used to manage
security-manager (ie. some TV images), this can result in update
script being not executed properly.

Added "set +e/set -e" before each systemctl invocation.

With this set of changes, it is assumed that whatever mechanism
is actually used to manage security-manager service, it is ensuring
that the daemon is NOT running when updates are being executed and that
it IS started after the update.

Updated scripts will try to lock the $TZ_SYS_RUN/lock/security-manager.lock
file, usually taken by daemon at its startup; if that fails,
updates will exit with an error.

Change-Id: If452415465a6c31ba7360f4b0272d51708602242

3 years agoChange FileLocker implemenation from POSIX to libc flocks 81/246181/2
Tomasz Swierczek [Mon, 26 Oct 2020 10:07:14 +0000 (11:07 +0100)]
Change FileLocker implemenation from POSIX to libc flocks

Thanks to this change, same locking could be used in sh/bash
scripts and in security-manager daemon (which previously
used the POSIX-based boost locks).

Change-Id: Ia4f2a5251d3556a40a68234fc2dc1ea51ac48188

3 years agoRelease 1.6.11 40/246040/1 submit/tizen/20201022.113306
Konrad Lipinski [Thu, 22 Oct 2020 11:29:17 +0000 (13:29 +0200)]
Release 1.6.11

* Apply private sharing rules before relabeling

Change-Id: I19d5882969ba5f65049e014b89f7dafd5534fca4

3 years agoApply private sharing rules before relabeling 60/245960/2
Konrad Lipinski [Tue, 20 Oct 2020 13:35:20 +0000 (15:35 +0200)]
Apply private sharing rules before relabeling

Prior to this commit, applyPrivatePathSharing does this:
1. Relabel a privately shared file.
2. Enable the package to rwxat the file's label.

Thus, there's a window between steps 1 & 2 where the package is unable
to access the file. This can be remedied by changing the order to:
1. Enable the package to rwxat the file's label.
2. Relabel the privately shared file.

The change preserves current semantics post-return but eliminates the
window.

The context:

Reportedly, the utc_rpc_port_set_private_sharing_array_p TCT test has
revealed a possibility of a race condition where a package owner would
get a smack access error when trying to unlink one of its own privately
shared files. This has reportedly happened on TM1 and some unspecified
TV product.

HQ inserted a 10ms sleep into ServiceImpl::applyPrivatePathSharing right
before return and, reportedly, it seems to have fixed the issue. They
seem partial to the assumption that the root cause is related to a race
condition in the kernel (as in: smack rules are being applied with a
delay). Thus, an idea for a possible solution involved checking smack
access client-side to make sure all is well before private sharing is
considered applied.

Given the fact that smack has been in place for quite some time now, I
find the possibility of a race condition unlikely. Unfortunately, I
haven't been able to prove anything. I couldn't reproduce the problem
and failed to find any obvious faults in the TCT test.

If there is a race condition, checking smack access client-side may not
be enough (it would only guarantee the client process or thread to be
race-free, TCT tests or the platform may need stronger guarantees). I'm
not inclined to do that unless there's proof. Such messy defensive code
tends to do more harm then good, especially if the race condition is
elsewhere.

Change-Id: I0a57edd6535eb1889d9bb8e5aaa6ddab58ca7009

3 years agoRelease 1.6.10 97/245897/1 submit/tizen/20201019.101508
Tomasz Swierczek [Mon, 19 Oct 2020 09:07:58 +0000 (11:07 +0200)]
Release 1.6.10

* Change author labels recursively in the upgrade script.
* Increase timeout waiting for signal delivery to 2 seconds

Change-Id: I6221d76c44eef78cb33f3d75f1b5bec52fac13df

3 years agoChange author labels recursively in the upgrade script. 79/245879/2
jin-gyu.kim [Mon, 19 Oct 2020 06:12:42 +0000 (15:12 +0900)]
Change author labels recursively in the upgrade script.

SMACK labels of all resources in trusted directory should be updated.

Change-Id: I992ac67fbcb635455fd5eda93e9d8f1a1d0da5a1

3 years agoIncrease timeout waiting for signal delivery to 2 seconds 90/245890/1
Tomasz Swierczek [Mon, 19 Oct 2020 06:57:18 +0000 (08:57 +0200)]
Increase timeout waiting for signal delivery to 2 seconds

The prepare_app is synchronizing threads security attributes in app
candidate process, which can be multithreaded. Security-Manager's
implementation mimics implementation in libc for smack label synchronization,
using signal handlers to do that.

In some systems under heavy load current timeout we're waiting for signal
delivery can be not enough, hence increasing the timeout.

Change-Id: I2b73c743fee61acbaeb834566a43b0f427218aab

3 years agoRelease 1.6.9 94/245794/1 accepted/tizen_6.0_unified_hotfix tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.115253 accepted/tizen/6.0/unified/hotfix/20201103.003302 accepted/tizen/unified/20201016.015201 submit/tizen/20201016.010710 submit/tizen_6.0/20201029.205104 submit/tizen_6.0_hotfix/20201102.192504 submit/tizen_6.0_hotfix/20201103.114804 tizen_6.0.m2_release
jin-gyu.kim [Fri, 16 Oct 2020 00:58:03 +0000 (09:58 +0900)]
Release 1.6.9

* Fix a typo in privilege-smack.list

Change-Id: Ibd8eb6ad3cd7ecba214106ee56704e08b88999a1

3 years agoFix a typo in privilege-smack.list 92/245792/2
jin-gyu.kim [Fri, 16 Oct 2020 00:51:06 +0000 (09:51 +0900)]
Fix a typo in privilege-smack.list

System::Privilege:AppDebugging -> System::Privilege::AppDebugging

Change-Id: I4307d3d93aff5b068e8f7923d72a6e5182f4becc

3 years agoRelease 1.6.8 36/245136/1 accepted/tizen/unified/20201006.044326 submit/tizen/20201002.165726
Mateusz Cegielka [Fri, 2 Oct 2020 13:14:52 +0000 (15:14 +0200)]
Release 1.6.8

* Fix segfault when iterating directories
* Remove unused code from sha1.c
* Revert "Add listing running apps based on namespace"
* Remove redundant author name from db

Change-Id: I3ba9a55a02ff08a48563ec3941fc8adf904a4fa9

3 years agoFix segfault when iterating directories 83/244983/5
Mateusz Cegielka [Mon, 28 Sep 2020 16:25:51 +0000 (18:25 +0200)]
Fix segfault when iterating directories

Code used for iterating directories recursively with Boost calls .pop()
if the iteration returns an error, so that it exits the current
directory and continues the iteration. However, this can cause
segmentation faults, and if it doesn't, it causes some other directories
to be indeterministically skipped instead.

What is the proper way to do this then...? Boost apparently does not
place too much focus on stability, because the behaviour is different in
every version I checked (1.65.0 from Ubuntu 18.04, 1.71.0 from Tizen and
1.72.0 from Arch). Also, since 1.72.0 it'll be impossible to both
continue the iteration and log that anything was wrong.

I changed the behaviour to stop iteration on errors and return an
internal error instead. The immediate reason is making sure a Boost
update won't break this code, but a system service receiving filesystem
errors in directories it created is a pathological case indicating other
problems with system configuration that should not be accepted.

Change-Id: I69b7fb75f2b58d0ca1418b6bbb3ccd2480296918

3 years agoRemove unused code from sha1.c 89/244989/4
Krzysztof Jackiewicz [Mon, 28 Sep 2020 18:23:31 +0000 (20:23 +0200)]
Remove unused code from sha1.c

Change-Id: I28c8f71b8e6c7bc4a98dc7e43ebfaba099351c40

3 years agoRevert "Add listing running apps based on namespace" 88/242888/4
Dariusz Michaluk [Tue, 1 Sep 2020 11:50:30 +0000 (13:50 +0200)]
Revert "Add listing running apps based on namespace"

It seems that this tool is unused.

This reverts commit 1a680bb1d2592a4110ca5d026c06dd11222d4e7c.

Change-Id: Ic7bd3f469a771d97e6a07af21912cd33140be46c

3 years agoRemove redundant author name from db 82/244982/3
Krzysztof Jackiewicz [Mon, 28 Sep 2020 12:01:51 +0000 (14:01 +0200)]
Remove redundant author name from db

Remove author's name from db as it's no longer needed. Make few minor changes
related to author.

Change-Id: I03f195298f6aa69d970f5d384b2ab441220f82e4

3 years agoRelease 1.6.7 07/244507/3 accepted/tizen/unified/20200922.034822 submit/tizen/20200921.110446
Tomasz Swierczek [Mon, 21 Sep 2020 05:48:51 +0000 (07:48 +0200)]
Release 1.6.7

* Optimize loading group information.
* Fix author_id mismatch after DB upgrade

Change-Id: I16cc8e235ea1f39a8974df2f90f12341cbb1d0b0

3 years agoOptimize loading group information. 02/243802/5
jin-gyu.kim [Thu, 10 Sep 2020 07:11:32 +0000 (07:11 +0000)]
Optimize loading group information.

Store group ids in a new configuartion file to avoid calculating it every time.
Those are written in $POLICY_PATH/group-id.list when policy rpm is installed.
These changes will speed up about 10 times for calulating group ids.

Change-Id: I0d71a44fdb7513a1c63c107062bfbe344b6889e8

3 years agoFix author_id mismatch after DB upgrade 17/239217/16
Dariusz Michaluk [Mon, 20 Jul 2020 12:20:07 +0000 (14:20 +0200)]
Fix author_id mismatch after DB upgrade

author_id is a DB table primary key and depends on apps instalation
order. Instead of using author_id in SMACK label, use 64 bits (16 character string)
of SHA1(author_name) in hex format.

This commit includes:
- sqlite3-sha1 extension copied from:
  https://github.com/sqlite/sqlite/blob/master/ext/misc/sha1.c
- new DB schema and migration script,
- rules loader adjustment to new SMACK label,
- filesystem (SECURITY_MANAGER_PATH_TRUSTED_RW) relabeling,
- app instalation changes.

Change-Id: I4f478e0b9dfde06ef752d250d5bc7ef3183cde19

3 years agoRelease 1.6.6 62/244162/2 accepted/tizen/unified/20200916.121703 submit/tizen/20200915.110745
Tomasz Swierczek [Tue, 15 Sep 2020 09:46:01 +0000 (11:46 +0200)]
Release 1.6.6

* Add configuration for appdebugging & internet Smack-controlled privileges
* Calculate application privilege level based on manifest data passed by installer
* Remove unused GetAuthorIdByName()

Change-Id: I53d3b6eab4d32fca6ff97e7f9681fded1fb6c323

3 years agoAdd configuration for appdebugging & internet Smack-controlled privileges 66/240566/3
Tomasz Swierczek [Fri, 7 Aug 2020 12:46:27 +0000 (14:46 +0200)]
Add configuration for appdebugging & internet Smack-controlled privileges

1st step in changing nether to Smack-based network access control
is to provide alternative configuration.

Change-Id: I811750af88a68b85cb7454d53b536a22884cdd6a

3 years agoCalculate application privilege level based on manifest data passed by installer 94/240694/4
Tomasz Swierczek [Mon, 10 Aug 2020 12:22:35 +0000 (14:22 +0200)]
Calculate application privilege level based on manifest data passed by installer

privilege-checker soon will need the cert-level information to calculate
application privilege attributes (blacklisted or privacy).

This cert-level will be, in target solution, passed as installation argument to
install request (see commit eb065339daf1ed9b091add719128f64e2372fd0e).

However, because that API was only recently introduced,
simply storing this data in security-manager.db at app install time and then
reusing it at userInit stage will not do the trick in a FOTA scenario (userInit
called after a FOTA where some apps are already in the DB).

Preparing a new DB field and running a migration script to calculate that field could
be a solution to the problem, but it would require additional sql query to get
application privilege-level inside implementation of userInit routine.

Alternative solution, exercised by this patch, is to rely on the installer,
which seems to be always adding the:

http://tizen.org/privilege/internal/default/[public | partner | platform]

privileges to install request, depending on the actual privilege level of package.

Since CynaraAdmin::userInit already has the global manifest bucket listed in memory,
there's no need for additional DB fetch - only one more iteration over the list to get
the highest privilege level available for given app.

Change-Id: Ib860e7f4d09e7f434197ddc08ae3777a119734d0

3 years agoRemove unused GetAuthorIdByName() 42/238942/5
Dariusz Michaluk [Mon, 20 Jul 2020 13:59:19 +0000 (15:59 +0200)]
Remove unused GetAuthorIdByName()

Change-Id: Ie83236411ece80754f0edd1428aedfda13796098

3 years agoRelease 1.6.5 (modified) 19/241419/1 accepted/tizen/unified/20200821.042433 submit/tizen/20200820.051038
Yunjin Lee [Thu, 20 Aug 2020 04:32:13 +0000 (13:32 +0900)]
Release 1.6.5 (modified)

* Add setting package type and privilege level in app install cmd
* Add core privilege: network.route

* Previous release commit missed 1 commit to include but merged hence
made modified release commit to fix that

Change-Id: Id4dc8cfa73290d8b70d6caa8321f70616a547939
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
3 years agoRelease 1.6.5 29/241329/2
Yunjin Lee [Wed, 19 Aug 2020 07:43:22 +0000 (16:43 +0900)]
Release 1.6.5

* Add core privilege: network.route

Change-Id: Iab41934cc11f55fb6f5227d876c08b991182160d

3 years agoAdd setting package type and privilege level in app install cmd 77/240477/2
Mateusz Cegielka [Thu, 6 Aug 2020 13:17:59 +0000 (15:17 +0200)]
Add setting package type and privilege level in app install cmd

Patch I518eb4524c9c1f3ff2e6d68ea25c037591f6634b has added two new
properties that can be set when installing an application. However, the
cmd tool used for installing applications was not updated.

This patch adds the missing options to the security-manager-cmd tool.

Change-Id: I02b00a75528e870be5f22e6d37cb49796b95fd82

3 years agoAdd core privilege: network.route 96/241296/2
Yunjin Lee [Wed, 19 Aug 2020 05:21:29 +0000 (14:21 +0900)]
Add core privilege: network.route

- network.route: With this privilege, app can add or remove route table
entries.

Change-Id: Ia97c7fb018f5522d60b41c1055677b2e6a544e5f
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
3 years agoRelease 1.6.4 64/239764/1 accepted/tizen/unified/20200731.145757 submit/tizen/20200730.095352
Dariusz Michaluk [Wed, 29 Jul 2020 12:18:46 +0000 (14:18 +0200)]
Release 1.6.4

* Switch security-manager to dual license (Apache 2.0 or MIT)
* Remove unneeded dependencies from nss plugin
* Test recently added queries to privilege database

Change-Id: I9ee77eb102771a6ef388331e5d15fb5237d46fdc

3 years agoSwitch security-manager to dual license (Apache 2.0 or MIT) 19/239419/7
Dariusz Michaluk [Fri, 24 Jul 2020 10:41:33 +0000 (12:41 +0200)]
Switch security-manager to dual license (Apache 2.0 or MIT)

Change-Id: Ic6566ca8fe012b4c4ebba2a411c04976c70b1abc

3 years agoRemove unneeded dependencies from nss plugin 11/239411/3
Dariusz Michaluk [Fri, 24 Jul 2020 09:59:51 +0000 (11:59 +0200)]
Remove unneeded dependencies from nss plugin

Dlog dependency was replaced by systemd journal on HQ request.

Change-Id: Ibb8ab3ba11ef9295721cfedfcbc0336dadf5d2bb

3 years agoTest recently added queries to privilege database 11/238311/1
Mateusz Cegielka [Fri, 10 Jul 2020 14:19:53 +0000 (16:19 +0200)]
Test recently added queries to privilege database

The PrivilegeDb class contains wrappers for running SQLite requests.
Since unit tests for it were created, more kinds of supported
statements have been added, but the tests were not updated.

I have added new tests that cover the GetAppPkgInfo, GetUserAppsFromPkg
SetSharedROPackage and IsUserPkgInstalled queries. I have also modified
existing privilege license tests to also cover
GetLicenseForClientPrivilegeAndPkg and AddAppDefinedPrivileges queries.

Change-Id: I3b43942f579cfc692b44203a2ea99b8c41d7be80

3 years agoRelease 1.6.3 74/238274/1 submit/tizen/20200710.130420
Tomasz Swierczek [Fri, 10 Jul 2020 06:51:59 +0000 (08:51 +0200)]
Release 1.6.3

* Fix CheckProperDrop tests
* Reimplement prepare_app proper drop checking
* Add smack-rules positive tests
* Enhance testability of TemplateManager class
* Add logging classes to unit tests
* Add unit tests for template manager class
* Remove unused code from sql_connection.cpp
* Add negative test cases wherever possible
* Add unit tests for functions in utils.cpp and other files
* Add tests for service_impl_utils.cpp functions
* Remove almost unused code from filesystem.cpp/.h
* Remove unused code from filesystem.cpp/.h
* Add test cases for filesystem.cpp functions
* Set C++ 17 flags
* Categorize unit test cases as negative or positive
* Disable assert() for release builds

Change-Id: I2871e378cf3f1002098df774b05fc7ee9b7b17eb

3 years agoFix CheckProperDrop tests 18/236218/8
Konrad Lipinski [Mon, 15 Jun 2020 15:31:10 +0000 (17:31 +0200)]
Fix CheckProperDrop tests

Moved into a separate commit at a reviewer's request.

Accommodate the new implementation:
* Run each test inside a fork() so that caps can be freely zeroed.
* Add namespace unsharing, uid, gid and groups tests.

Change-Id: Ic8c608b2cd301b2898cbcd3b1ae3dcc3f62cecda

3 years agoReimplement prepare_app proper drop checking 92/231392/57
Konrad Lipinski [Tue, 21 Apr 2020 17:32:17 +0000 (19:32 +0200)]
Reimplement prepare_app proper drop checking

Procps-ng does not reliably check for errors. They are for the most part
silently ignored. The only way to approximately check for success is by
checking errno. That's what we've been doing up till now. However, errno
is not mentioned in the contract at all. Syscalls that succeed may zero
errno and mask prior errors.

Pre-3.12 kernels require CAP_SYS_PTRACE for task namespace inspection.
In particular, contemporary TM1 images feature a 3.10 kernel. On such
devices, PROC_FILLNS may result in errno being set to EACCES (unless
overwritten as per the previous paragraph). Such is the case on TM1,
making CheckProperDrop::checkThreads() fail whenever there are two or
more threads.

Checking for identical caps is not enough to ensure proper drop. A rogue
thread may survive sync_threads_internal() (which is racy by nature),
use capset() to set main thread's caps to zero, then terminate before
CheckProperDrop::getThreads() starts due to a lucky interleaving. This
can be guarded against by mandating capabilities to be zeroed for all
threads.

* Replace procps-ng usage with local code.
* Assert zero caps instead of identical caps.
* Refrain from checking pid and user namespaces, kernel guarantees
  consistency across threads (see man unshare(2)).
* Compute the set of checked namespace kinds as a bitmask at manager
  startup, ipc the bitmask to clients in prepare_app return payload.
* Set bitmask to zero for pre-3.12 kernels that require CAP_SYS_PTRACE
  for task namespace inspection.
* Disable compilation of test_check_proper_drop.cpp. The tests were
  written under the assumption that caps do not have to be zeroed. This
  is no longer the case. Zeroing caps requires fork support, there are
  also new edge cases to test. This makes the needed change substantial.
  By review request it will be included in a future commit.

Change-Id: I4814cfd92dc524c02d87926236d8beb97d633c82