public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [bz 22342] patch: fix netgroup cache keys
@ 2018-03-01 22:11 DJ Delorie
  2018-03-01 23:12 ` Carlos O'Donell
  0 siblings, 1 reply; 9+ messages in thread
From: DJ Delorie @ 2018-03-01 22:11 UTC (permalink / raw)
  To: libc-alpha


Functionality tested on RHEL 7.  Regression tested on Fedora 26.

	[BZ #22342]
	* nscd/netgroupcache.c (addinnetgrX): Include trailing NUL in
	key value.

diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index b832c9315f..2f187b208c 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -480,7 +480,7 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
 {
   const char *group = key;
   key = (char *) rawmemchr (key, '\0') + 1;
-  size_t group_len = key - group - 1;
+  size_t group_len = key - group;
   const char *host = *key++ ? key : NULL;
   if (host != NULL)
     key = (char *) rawmemchr (key, '\0') + 1;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [bz 22342] patch: fix netgroup cache keys
  2018-03-01 22:11 [bz 22342] patch: fix netgroup cache keys DJ Delorie
@ 2018-03-01 23:12 ` Carlos O'Donell
  2018-03-01 23:21   ` DJ Delorie
  0 siblings, 1 reply; 9+ messages in thread
From: Carlos O'Donell @ 2018-03-01 23:12 UTC (permalink / raw)
  To: DJ Delorie, libc-alpha

On 03/01/2018 02:11 PM, DJ Delorie wrote:
> Functionality tested on RHEL 7.  Regression tested on Fedora 26.
> 
> 	[BZ #22342]
> 	* nscd/netgroupcache.c (addinnetgrX): Include trailing NUL in
> 	key value.
> 
> diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
> index b832c9315f..2f187b208c 100644
> --- a/nscd/netgroupcache.c
> +++ b/nscd/netgroupcache.c
> @@ -480,7 +480,7 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
>  {
>    const char *group = key;
>    key = (char *) rawmemchr (key, '\0') + 1;
> -  size_t group_len = key - group - 1;
> +  size_t group_len = key - group;
>    const char *host = *key++ ? key : NULL;
>    if (host != NULL)
>      key = (char *) rawmemchr (key, '\0') + 1;
> 

Why is this correct?

A good submission includes a justification that the
fix is logically what is required.

We do not want to paper over a problem just by testing
that a given change makes things better.

Do we understand what the problem is?

The bug report appears to make the claim that there are
two paths in the code, one which adds to the cache with
the null included in the length, and another which doesn't,
which obviously results in a cache miss.

Is that the final case we are fixing here? Can you describe
this a bit more for the commit message?

Please post a v2 with the commit message you intend to use
please.

-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [bz 22342] patch: fix netgroup cache keys
  2018-03-01 23:12 ` Carlos O'Donell
@ 2018-03-01 23:21   ` DJ Delorie
  2018-03-02  0:17     ` Carlos O'Donell
  0 siblings, 1 reply; 9+ messages in thread
From: DJ Delorie @ 2018-03-01 23:21 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha

"Carlos O'Donell" <carlos@redhat.com> writes:
> Why is this correct?

As noted in the referenced BZ, this is the only key in the database that
doesn't include its trailing NUL.  In this particular case, it's
problematic because there are *two* types of entries in the netgroup
cache, and when the keys don't match the cache aging and timeouts don't
work right.

> Please post a v2 with the commit message you intend to use
> please.

Will do.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [bz 22342] patch: fix netgroup cache keys
  2018-03-01 23:21   ` DJ Delorie
@ 2018-03-02  0:17     ` Carlos O'Donell
  2018-03-02  2:28       ` [bz 22342] patch V2: " DJ Delorie
  0 siblings, 1 reply; 9+ messages in thread
From: Carlos O'Donell @ 2018-03-02  0:17 UTC (permalink / raw)
  To: DJ Delorie; +Cc: libc-alpha

On 03/01/2018 03:21 PM, DJ Delorie wrote:
> "Carlos O'Donell" <carlos@redhat.com> writes:
>> Why is this correct?
> 
> As noted in the referenced BZ, this is the only key in the database that
> doesn't include its trailing NUL.  In this particular case, it's
> problematic because there are *two* types of entries in the netgroup
> cache, and when the keys don't match the cache aging and timeouts don't
> work right.

What are the two types of entries? How do they arrive at the database?
What is the other code path that adds the null?

You are -><- close to having what I would want for a good commit message
which explains the exact source of the problem and makes it immediately
obvious that the fix has to be correct.

>> Please post a v2 with the commit message you intend to use
>> please.
> 
> Will do.
> 


-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [bz 22342] patch V2: fix netgroup cache keys
  2018-03-02  0:17     ` Carlos O'Donell
@ 2018-03-02  2:28       ` DJ Delorie
  2018-03-02  3:13         ` Carlos O'Donell
  0 siblings, 1 reply; 9+ messages in thread
From: DJ Delorie @ 2018-03-02  2:28 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha


Unlike other nscd caches, the netgroup cache contains two types of
records - those for "iterate through a netgroup" (i.e. setnetgrent())
and those for "is this user in this netgroup" (i.e. innetgr()),
i.e. full and partial records.  The timeout code assumes these records
have the same key for the group name, so that the collection of records
that is "this netgroup" can be expired as a unit.

However, the keys are not the same, as the in-netgroup key is generated
by nscd rather than being passed to it from elsewhere, and is generated
without the trailing NUL.  All other keys have the trailing NUL, and as
noted in the linked BZ, debug statements confirm that two keys for the
same netgroup are added to the cache with two different lengths.

The result of this is that as records in the cache expire, the purge
code only cleans out one of the two types of entries, resulting in
stale, possibly incorrect, and possibly inconsistent cache data.

The patch simply includes the existing NUL in the computation for the
key length ('key' points to the char after the NUL, and 'group' to the
first char of the group, so 'key-group' includes the first char to the
NUL, inclusive).

	[BZ #22342]
 	* nscd/netgroupcache.c (addinnetgrX): Include trailing NUL in
 	key value.

diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index b832c9315f..2f187b208c 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -480,7 +480,7 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
 {
   const char *group = key;
   key = (char *) rawmemchr (key, '\0') + 1;
-  size_t group_len = key - group - 1;
+  size_t group_len = key - group;
   const char *host = *key++ ? key : NULL;
   if (host != NULL)
     key = (char *) rawmemchr (key, '\0') + 1;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [bz 22342] patch V2: fix netgroup cache keys
  2018-03-02  2:28       ` [bz 22342] patch V2: " DJ Delorie
@ 2018-03-02  3:13         ` Carlos O'Donell
  2018-03-02  4:25           ` DJ Delorie
  0 siblings, 1 reply; 9+ messages in thread
From: Carlos O'Donell @ 2018-03-02  3:13 UTC (permalink / raw)
  To: DJ Delorie; +Cc: libc-alpha

On 03/01/2018 06:28 PM, DJ Delorie wrote:
> 
> Unlike other nscd caches, the netgroup cache contains two types of
> records - those for "iterate through a netgroup" (i.e. setnetgrent())
> and those for "is this user in this netgroup" (i.e. innetgr()),
> i.e. full and partial records.  The timeout code assumes these records
> have the same key for the group name, so that the collection of records
> that is "this netgroup" can be expired as a unit.
> 
> However, the keys are not the same, as the in-netgroup key is generated
> by nscd rather than being passed to it from elsewhere, and is generated
> without the trailing NUL.  All other keys have the trailing NUL, and as
> noted in the linked BZ, debug statements confirm that two keys for the
> same netgroup are added to the cache with two different lengths.
> 
> The result of this is that as records in the cache expire, the purge
> code only cleans out one of the two types of entries, resulting in
> stale, possibly incorrect, and possibly inconsistent cache data.
> 
> The patch simply includes the existing NUL in the computation for the
> key length ('key' points to the char after the NUL, and 'group' to the
> first char of the group, so 'key-group' includes the first char to the
> NUL, inclusive).

Perfect. Please commit with this explanation as the commit message.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> 	[BZ #22342]
>  	* nscd/netgroupcache.c (addinnetgrX): Include trailing NUL in
>  	key value.
> 
> diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
> index b832c9315f..2f187b208c 100644
> --- a/nscd/netgroupcache.c
> +++ b/nscd/netgroupcache.c
> @@ -480,7 +480,7 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
>  {
>    const char *group = key;
>    key = (char *) rawmemchr (key, '\0') + 1;
> -  size_t group_len = key - group - 1;
> +  size_t group_len = key - group;
>    const char *host = *key++ ? key : NULL;
>    if (host != NULL)
>      key = (char *) rawmemchr (key, '\0') + 1;
> 


-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [bz 22342] patch V2: fix netgroup cache keys
  2018-03-02  3:13         ` Carlos O'Donell
@ 2018-03-02  4:25           ` DJ Delorie
  2018-03-02 17:20             ` Joseph Myers
  0 siblings, 1 reply; 9+ messages in thread
From: DJ Delorie @ 2018-03-02  4:25 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha


"Carlos O'Donell" <carlos@redhat.com> writes:
> Perfect. Please commit with this explanation as the commit message.

Done.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [bz 22342] patch V2: fix netgroup cache keys
  2018-03-02  4:25           ` DJ Delorie
@ 2018-03-02 17:20             ` Joseph Myers
  2018-03-02 18:11               ` DJ Delorie
  0 siblings, 1 reply; 9+ messages in thread
From: Joseph Myers @ 2018-03-02 17:20 UTC (permalink / raw)
  To: DJ Delorie; +Cc: Carlos O'Donell, libc-alpha

On Thu, 1 Mar 2018, DJ Delorie wrote:

> "Carlos O'Donell" <carlos@redhat.com> writes:
> > Perfect. Please commit with this explanation as the commit message.
> 
> Done.

If the commit fixes the bug, please resolve it as FIXED with target 
milestone set to 2.28.  (If a commit mentions a bug but does not complete 
fixing it, I strongly advise making that explicit in the commit message so 
it's obvious to readers that the bug is deliberately not marked as FIXED.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [bz 22342] patch V2: fix netgroup cache keys
  2018-03-02 17:20             ` Joseph Myers
@ 2018-03-02 18:11               ` DJ Delorie
  0 siblings, 0 replies; 9+ messages in thread
From: DJ Delorie @ 2018-03-02 18:11 UTC (permalink / raw)
  To: Joseph Myers; +Cc: carlos, libc-alpha


Thanks, I keep forgetting that step.  Done :-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-03-02 18:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-01 22:11 [bz 22342] patch: fix netgroup cache keys DJ Delorie
2018-03-01 23:12 ` Carlos O'Donell
2018-03-01 23:21   ` DJ Delorie
2018-03-02  0:17     ` Carlos O'Donell
2018-03-02  2:28       ` [bz 22342] patch V2: " DJ Delorie
2018-03-02  3:13         ` Carlos O'Donell
2018-03-02  4:25           ` DJ Delorie
2018-03-02 17:20             ` Joseph Myers
2018-03-02 18:11               ` DJ Delorie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).