lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 23 Aug 2020 16:54:53 +0100
From:   Matthew Wilcox <willy@...radead.org>
To:     Giuseppe Scrivano <gscrivan@...hat.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Xu Wang <vulab@...as.ac.cn>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, Tejun Heo <tj@...nel.org>
Subject: Re: [PATCH] hugetlb_cgroup: convert comma to semicolon

On Sun, Aug 23, 2020 at 04:21:30PM +0100, Matthew Wilcox wrote:
> On Wed, Aug 19, 2020 at 10:14:11AM +0200, Giuseppe Scrivano wrote:
> > >> -	cft->file_offset = offsetof(struct hugetlb_cgroup, events_file[idx]),
> > >> +	cft->file_offset = offsetof(struct hugetlb_cgroup, events_file[idx]);
> > >>  	cft->flags = CFTYPE_NOT_ON_ROOT;
> > 
> > I think in this case having two expressions as part of the same
> > statement is equivalent to having two separate statements.  Both
> > cft->file_offset and cft->flags get the expected value.
> 
> That's not how the comma operator works.
> 
> It will evaluate offsetof(struct hugetlb_cgroup, events_file[idx]) and
> then discard the result.  Since it has no side-effects, this is effectively
> doing:
> 
> 	cft->file_offset = cft->flags = CFTYPE_NOT_ON_ROOT;

_oh_.  I tested this.  I'm wrong because the comma operator is at lower
precedence than assignment.

Testcase:

struct a {
  int x;
  int y;
};

void g(struct a *a) {
  a->x = 1,
  a->y = 0;
}

void h(struct a *a) {
  a->x = (1,
  a->y = 0);
}

test.c: In function ‘h’:
test.c:12:12: warning: left-hand operand of comma expression has no effect [-Wunused-value]
   12 |   a->x = (1,
      |            ^

0000000000000000 <g>:
   0:	48 c7 07 01 00 00 00 	movq   $0x1,(%rdi)
   7:	c3                   	retq   
   8:	0f 1f 84 00 00 00 00 	nopl   0x0(%rax,%rax,1)
   f:	00 

0000000000000010 <h>:
  10:	48 c7 07 00 00 00 00 	movq   $0x0,(%rdi)
  17:	c3                   	retq   

So there's no bug here!  It's just confusing, so should be fixed.

(I think Andrew was confused too ;-)

Powered by blists - more mailing lists