Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache: Check for max_id/min_id in cache_req #449

Closed
wants to merge 1 commit into from

Conversation

code-with-amitk
Copy link
Contributor

The cache_req code doesn't check the min_id/max_id
boundaries for requests by ID.
Extending the .lookup_fn function in each plugin
that searches by ID for a check that returns 0
if the entry is out of the range.

Resolves: https://pagure.io/SSSD/sssd/issue/3569

@centos-ci
Copy link

Can one of the admins verify this patch?

1 similar comment
@centos-ci
Copy link

Can one of the admins verify this patch?

Copy link
Contributor

@fidencio fidencio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amitkumar50, as usual, thanks a lot for your contribution!

I've asked a few questions inline.

@@ -4909,7 +4909,9 @@ errno_t sysdb_search_object_by_id(TALLOC_CTX *mem_ctx,
if (filter == NULL) {
return ENOMEM;
}

if (id > 20000 || id < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 20000 was chosen? Please, add a new #define with a meaningful name (or check if we already have one and use it) in order to have things more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why 20000 was chosen? I don't understand where the 20000 comes from.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked the code and seems that the check you'd like to do is based on domain.
So, you'd have to do something like (not tested):

if ((domain->max_id != 0 && id > domain->max_id) ||  id < domain->min_id ) {
...
}

The reason for this check is because:

  • min_id and max_id may be defined by domain through sssd.conf
  • defining max_id = 0 means there's no limit for the max_id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last but not least, I'd expect at least some debug message added warning that min_id/max_id conditions are not match.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'd like to hear from @pbrezina whether he thinks would be better to do this check at the sysdb level or at the cache_req level.

@@ -4909,7 +4909,9 @@ errno_t sysdb_search_object_by_id(TALLOC_CTX *mem_ctx,
if (filter == NULL) {
return ENOMEM;
}

if (id > 20000 || id < 0) {
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return EOK instead of 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per https://pagure.io/SSSD/sssd/issue/3569
for a check that returns EOK but a NULL result if the entry is out of the range.

This is Error case. I believe returning EOK would not be good?
Also typedef int errno_t; So returning NULL would cause warning.
Again EOK is 0 and NULL is also 0. I believe we should only return 0 value on error path, since on good path we should allow function to go a head.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOK is 0. But it's way clear in the code if I read EOK instead of 0 as I know that EOK is OK and zero may mean anything else.

@@ -364,7 +364,7 @@ errno_t sysdb_getpwuid_with_views(TALLOC_CTX *mem_ctx,
uid_t uid,
struct ldb_result **res)
{
int ret;
int ret = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you decided to set ret to zero here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At end of function, inside done label, If we not setting any value of ret, It would throw uninitialized warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, please, set the ret to EOK in the appropriate place (just before calling "goto done")

@@ -374,7 +374,9 @@ errno_t sysdb_getpwuid_with_views(TALLOC_CTX *mem_ctx,
DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
return ENOMEM;
}

if (uid > 20000 || uid < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 20000 was chosen? Please, add a new #define with a meaningful name (or check if we already have one and use it) in order to have things more clear.

@@ -949,7 +951,7 @@ int sysdb_getgrgid_with_views(TALLOC_CTX *mem_ctx,
struct ldb_result **res)
{
TALLOC_CTX *tmp_ctx;
int ret;
int ret = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you decided to set ret to zero here?

@@ -958,7 +960,9 @@ int sysdb_getgrgid_with_views(TALLOC_CTX *mem_ctx,
if (!tmp_ctx) {
return ENOMEM;
}

if (gid > 20000 || gid < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 20000 was chosen? Please, add a new #define with a meaningful name (or check if we already have one and use it) in order to have things more clear.

@fidencio
Copy link
Contributor

ok to test

@jhrozek
Copy link
Contributor

jhrozek commented Nov 14, 2017

I'm sorry, but this patch is incorrect.

As I wrote in the ticket, you want to check the input id (data->id inside cache_req) against the domain min/max limits inside the lookup_fn function of plugins that search by ID.

My initial idea was to return a special error code (ERR_UID_OUTSIDE_RANGE?) so that the lookup wouldn't even continue. But this would only handle requests where we actually search the cache.

Alternatively, we could add another plugin method. Not sure which way is more preferred, what do you think, @pbrezina

@pbrezina
Copy link
Member

@jhrozek At this point, I think it will be better to wait for your cache req patches to come in. I think this check can be done during the phase where you check if the id is part of the domain. If it is outside the domain range, we can say it is not part of this domain.

Copy link
Contributor Author

@code-with-amitk code-with-amitk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrongly commited on this branch.

@jhrozek
Copy link
Contributor

jhrozek commented Nov 15, 2017

@pbrezina I'm still running some tests with my patches, but in general they are ready and published in my gc_uid branch.

btw see the downtream report - we were already asked for a backport to sssd-1-14, so while in general I'm OK with basing the patches to master atop mine (less work for me I guess :-)) we will also need patches for sssd-1-14.

@code-with-amitk
Copy link
Contributor Author

@jhrozek Thanks for comments.
So Shall I not work on this patch as of now?
Or instead of EOK define ERR_UID_OUTSIDE_RANGE in ./src/util/util_errors.h and return.

@@ -4909,7 +4909,6 @@ errno_t sysdb_search_object_by_id(TALLOC_CTX *mem_ctx,
if (filter == NULL) {
return ENOMEM;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line removal does not belong to this patch, can you remove this hunk from the patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry dint know how these creapt in. On my local checkout on branch I cannot see these.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still present in the current series.

@@ -374,7 +374,6 @@ errno_t sysdb_getpwuid_with_views(TALLOC_CTX *mem_ctx,
DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
return ENOMEM;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

if ((domain->id_max != 0 && data->id > domain->id_max)
|| (data->id < domain->id_min)) {
DEBUG(SSSDBG_OP_FAILURE, "gid exceeds min/max boundaries\n");
return EOK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you need to return some special error code here. Additionally, please check both id_max and id_min for being non-zero, like this:

 if ((domain->id_min && (data->id < domain->id_min)) ||
     (domain->id_max && (data->id > domain->id_max))) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please make the debug message level FUNC_DATA or something as low as that so that the debug message doesn't appear during normal operation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, please add a case handler into the switch statement in cache_req_search_cache() so that we only print a very low-level debug message and don't hit the "default" handler.

if ((domain->id_max != 0 && data->id > domain->id_max)
|| (data->id < domain->id_min)) {
DEBUG(SSSDBG_OP_FAILURE, "id exceeded min/max boundaries\n");
return EOK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as in the group lookup. I wonder if it makes sense to add a common function to avoid duplicating the same lines?

if ((domain->id_max != 0 && data->id > domain->id_max)
|| (data->id < domain->id_min)) {
DEBUG(SSSDBG_OP_FAILURE, "uid exceeds min/max boundaries\n");
return EOK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in the object and group lookup.

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amitkumar50 please see the review comments

@jhrozek
Copy link
Contributor

jhrozek commented Nov 29, 2017

Removing changes requested since a new patch had arrived

Copy link
Contributor

@fidencio fidencio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made some comments inline. Adding the "Changes Requested" label but still would like hear from @jhrozek whether the approach of the contributor is okay for him.

@@ -4909,7 +4909,6 @@ errno_t sysdb_search_object_by_id(TALLOC_CTX *mem_ctx,
if (filter == NULL) {
return ENOMEM;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still present in the current series.

@@ -374,7 +374,6 @@ errno_t sysdb_getpwuid_with_views(TALLOC_CTX *mem_ctx,
DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
return ENOMEM;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

DEBUG(SSSDBG_FUNC_DATA, "gid exceeds min/max boundaries\n");
return ERR_UID_OUTSIDE_RANGE;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function as it is will generate a warning due to the missing return for a non-void function. IOW, you need to return EOK in case of success.

@@ -64,6 +64,7 @@ cache_req_group_by_id_lookup(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result **_result)
{
cache_req_idminmax_check(data, domain);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that you want to check the return of this function and then decide what to do based on that.

@@ -90,6 +90,7 @@ cache_req_object_by_id_lookup(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result **_result)
{
cache_req_idminmax_check(data, domain);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -64,6 +64,7 @@ cache_req_user_by_id_lookup(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result **_result)
{
cache_req_idminmax_check(data, domain);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

@@ -137,6 +137,7 @@ enum sssd_errors {
ERR_SSL_FAILURE,
ERR_UNABLE_TO_VERIFY_PEER,
ERR_UNABLE_TO_RESOLVE_HOST,
ERR_UID_OUTSIDE_RANGE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you added a new error in util_errors.h, please, also to add a new string for this error on util_errors.c

The cache_req code doesn't check the min_id/max_id
boundaries for requests by ID.
Extending the .lookup_fn function in each plugin
that searches by ID for a check that returns 0
if the entry is out of the range.

Resolves: https://pagure.io/SSSD/sssd/issue/3569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants