Avoid odd behavior when clearing nonexistent SID

It's expected that clearSecureUserId is sometimes called with a userId
that doesn't currently have a Gatekeeper enrollment.  For example, this
happens whenever a user with no LSKF is removed.  gatekeeperd currently
has two odd behaviors when it's asked to do this.  First, it logs the
following message at ERROR level, which is not appropriate:

    E gatekeeperd: clear_sid: could not remove file [No such file or directory], attempting 0 write

Second, it writes 0 to the file /data/misc/gatekeeper/$userId.  This
makes this file exist even after the user has been removed, which
doesn't cause a real problem but is unexpected.

Fix both of these issues by making clear_sid() check for ENOENT.

Bug: 188702845
Bug: 268526331
Change-Id: Ib1b110f2502267004f5c945c28c98ae926b2a794
This commit is contained in:
Eric Biggers 2023-03-03 22:55:54 +00:00
parent 18b6e9b819
commit b4738b9e5d

View file

@ -151,7 +151,7 @@ class GateKeeperProxy : public BnGateKeeperService {
void clear_sid(uint32_t userId) {
char filename[21];
snprintf(filename, sizeof(filename), "%u", userId);
if (remove(filename) < 0) {
if (remove(filename) < 0 && errno != ENOENT) {
ALOGE("%s: could not remove file [%s], attempting 0 write", __func__, strerror(errno));
store_sid(userId, 0);
}