linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@openvz.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Pavel Emelyanov <xemul@parallels.com>,
	Serge Hallyn <serge.hallyn@canonical.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Kees Cook <keescook@chromium.org>, Tejun Heo <tj@kernel.org>,
	Andrew Vagin <avagin@openvz.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Andi Kleen <andi@firstfloor.org>,
	KOSAKI Motohiro <kosaki.motohiro@gmail.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Glauber Costa <glommer@parallels.com>,
	Matt Helsley <matthltc@us.ibm.com>,
	Pekka Enberg <penberg@kernel.org>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Vasiliy Kulikov <segoon@openwall.com>,
	Valdis.Kletnieks@vt.edu
Subject: Re: [patch cr 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v7
Date: Fri, 3 Feb 2012 12:35:30 +0400	[thread overview]
Message-ID: <20120203083530.GD1968@moon> (raw)
In-Reply-To: <20120203074656.GC30543@elte.hu>

On Fri, Feb 03, 2012 at 08:46:56AM +0100, Ingo Molnar wrote:
> 
> * Cyrill Gorcunov <gorcunov@openvz.org> wrote:
> 
> > +/* Comparision type */
> 
> > + * We don't expose real in-memory order of objects for security
> > + * reasons, still the comparision results should be suitable for
> > + * sorting. Thus, we obfuscate kernel pointers values (using random
> > + * cookies obtaned at early boot stage) and compare the production
> > + * instead.
> 
> > + * 0 - equal
> > + * 1 - less than
> > + * 2 - greater than
> > + * 3 - not equal but ordering unavailable (reserved for future)
> 
> Broken spelling in each of those comment blocks. Are these 
> comments write-only?

No, they are not write-only. I've fixed typos in first comment block,
though I don't understand what is wrong with 0,1,2,3 comments.

> 
> > +	/*
> > +	 * Tasks are looked up in caller's
> > +	 * PID namespace only.
> > +	 */
> 
> Could be a single line.
> 

Ok, will do so.

> > +
> > +	task1 = find_task_by_vpid(pid1);
> > +	if (!task1) {
> > +		rcu_read_unlock();
> > +		return -ESRCH;
> > +	}
> > +
> > +	task2 = find_task_by_vpid(pid2);
> > +	if (!task2) {
> > +		put_task_struct(task1);
> > +		rcu_read_unlock();
> > +		return -ESRCH;
> > +	}
> 
> This is not the standard pattern of how we do error paths ...

OK, I'll try to make it in standart way.

> 
> > +	/*
> > +	 * Note for all cases but the KCMP_FILE we
> > +	 * don't take any locks in a sake of speed.
> > +	 */
> 
> Spelling.

Not sure what you mean here, but I'll drop this comment
to eliminate this problem.

> 
> > +			get_random_bytes(&cookies[i][j],
> > +					 sizeof(cookies[i][j]));
> 
> ugly line break.
> 

Why? Looks pretty good to me. But sure I'll change it.

> > +late_initcall(kcmp_cookie_init);
> 
> any particular reason why this needs to be a late initcall?
> 

Grr! The late_initcall remained here from versions where I've
been playing with crypto hashes. Thanks, Ingo, I'll fix!

> > +
> > +clean:
> > +	$(E) "  CLEAN"
> > +	$(Q) rm -fr ./run_test
> > +	$(Q) rm -fr ./test-file
> 
> Needs buy-in from the kbuild guys.

I took breakpoint test as example. Maybe I should
send this test case code as a separate patch?

> 
> > +#ifdef CONFIG_X86_64
> > +#include <asm/unistd_64.h>
> > +#else
> > +#include <asm/unistd_32.h>
> > +#endif
> 
> Why is asm/unistd.h not good?
> 

With asm/unistd.h it fails to build because it requires the headers
to be installed first (ie headers_install target) so I though this
way would be more convenient, no?

> > +static long sys_kcmp(int pid1, int pid2, int type, int fd1, int fd2)
> > +{
> > +	return syscall(__NR_kcmp, (long)pid1, (long)pid2,
> > +		       (long)type, (long)fd1, (long)fd2);
> > +}
> 
> Why is a syscall that takes long arguments defined and called 
> with int and then cast over to long again?
> 

Just a habit, the args will be converted to long anyway,
so I don't see a problem here. Still I can drop them.

> > +		int pid2 = getpid();
> > +		int ret;
> > +
> > +		fd2 = open("test-file", O_RDWR, 0644);
> > +		if (fd2 < 0) {
> > +			perror("Can't open file");
> > +			exit(1);
> > +		}
> > +
> > +		/* An example of output and arguments */
> > +                printf("pid1: %6d pid2: %6d FD: %2d FILES: %2d VM: %2d FS: %2d "
> > +		       "SIGHAND: %2d IO: %2d SYSVSEM: %2d INV: %2d\n",
> 
> Visibly stray whitespaces.
> 
> > +		/* This one should return same fd */
> > +		ret = sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd1);
> > +		if (ret) {
> > +			printf("FAIL: 0 expected but %d returned\n", ret);
> > +			ret = -1;
> > +		} else
> > +			printf("PASS: 0 returned as expected\n");
> > +		exit(ret);
> 
> this is main(), what's wrong with the standard pattern of return 
> ret?
> 

It's fork'ed children.

> I don't know whether this code is correct, but the high amount 
> of basic cleanliness problems makes me worry about that.
> 

Code is correct. I'll clean up the nits you pointed.

	Cyrill

  reply	other threads:[~2012-02-03  8:35 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-30 14:09 [patch cr 0/4] [patch cr 0/@total@] Cyrill Gorcunov
2012-01-30 14:09 ` [patch cr 1/4] fs, proc: Introduce /proc/<pid>/task/<tid>/children entry v9 Cyrill Gorcunov
2012-01-30 14:09 ` [patch cr 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v7 Cyrill Gorcunov
2012-01-30 19:58   ` Jonathan Corbet
2012-01-30 21:07     ` Cyrill Gorcunov
2012-01-30 21:11     ` H. Peter Anvin
2012-02-02 23:26   ` Andrew Morton
2012-02-03  2:27     ` H. Peter Anvin
2012-02-03  7:09       ` Cyrill Gorcunov
2012-02-03  7:46   ` Ingo Molnar
2012-02-03  8:35     ` Cyrill Gorcunov [this message]
2012-02-03  9:09       ` Ingo Molnar
2012-02-03  9:22         ` Andrew Morton
2012-02-03  9:28           ` Cyrill Gorcunov
2012-02-03 17:32             ` H. Peter Anvin
2012-02-03 17:35               ` H. Peter Anvin
2012-02-03 17:42                 ` Cyrill Gorcunov
2012-02-03  9:52           ` Ingo Molnar
2012-02-03 10:07             ` [PATCH] SubmittingPatches: Increase the line length limit from 80 to 100 colums Ingo Molnar
2012-02-03 10:17               ` Pekka Enberg
2012-02-03 10:23                 ` Cyrill Gorcunov
2012-02-03 10:40               ` Alexey Dobriyan
2012-02-03 16:13               ` Tejun Heo
2012-02-03 16:39                 ` hpanvin@gmail.com
2012-02-03 17:56               ` Andi Kleen
2012-02-03 20:57               ` Andrew Morton
2012-02-03 21:00                 ` H. Peter Anvin
2012-02-03 21:06                 ` H. Peter Anvin
2012-02-04 13:08                 ` Ingo Molnar
2012-02-03 21:27               ` Linus Torvalds
2012-02-03 23:20                 ` [PATCH] checkpatch: Warn on code with 6+ tab indentation Joe Perches
2012-02-04  1:27                   ` Linus Torvalds
2012-02-04  1:33                     ` Joe Perches
2012-02-04  3:09                       ` Linus Torvalds
2012-02-04  3:21                         ` Joe Perches
2012-02-04  3:35                           ` Linus Torvalds
2012-02-04  3:58                             ` Joe Perches
2012-02-04  1:37                     ` Andrew Morton
2012-02-04  2:40                   ` Eric W. Biederman
2012-02-04  2:46                     ` Joe Perches
2012-02-04  4:45                   ` Tony Luck
2012-02-04  4:53                     ` Joe Perches
2012-02-04 13:03                   ` [PATCH, v2] checkpatch: Warn on code with 6+ tab indentation, remove 80col warning Ingo Molnar
2012-02-04 16:22                     ` Joe Perches
2012-02-04 18:02                       ` Ingo Molnar
2012-02-04 18:48                         ` Joe Perches
2012-02-04 18:54                           ` Pekka Enberg
2012-02-04 19:27                             ` Joe Perches
2012-02-04 19:32                               ` Pekka Enberg
2012-02-05 11:38                               ` Ingo Molnar
2012-02-05 16:21                                 ` Joe Perches
2012-02-05 18:13                                   ` Ingo Molnar
2012-02-05 19:01                                     ` [PATCH] checkpatch: Add line-length options, set default to 100 Joe Perches
2012-02-06 12:36                                       ` Dan Carpenter
2012-02-04  1:24                 ` [PATCH] SubmittingPatches: Increase the line length limit from 80 to 100 colums Randy Dunlap
2012-02-09 21:55               ` Jan Engelhardt
2012-02-09 22:09                 ` Joe Perches
2012-02-09 22:30                 ` Mark Brown
2012-01-30 14:09 ` [patch cr 3/4] c/r: procfs: add arg_start/end, env_start/end and exit_code members to /proc/$pid/stat Cyrill Gorcunov
2012-02-02 23:26   ` Andrew Morton
2012-02-03  7:11     ` Cyrill Gorcunov
2012-01-30 14:09 ` [patch cr 4/4] c/r: prctl: Extend PR_SET_MM to set up more mm_struct entries Cyrill Gorcunov
2012-02-02 23:27   ` Andrew Morton
2012-02-03  7:18     ` Cyrill Gorcunov
2012-02-02 23:26 ` [patch cr 0/4] [patch cr 0/@total@] Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120203083530.GD1968@moon \
    --to=gorcunov@openvz.org \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=avagin@openvz.org \
    --cc=ebiederm@xmission.com \
    --cc=eric.dumazet@gmail.com \
    --cc=glommer@parallels.com \
    --cc=hpa@zytor.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=keescook@chromium.org \
    --cc=kosaki.motohiro@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthltc@us.ibm.com \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    --cc=segoon@openwall.com \
    --cc=serge.hallyn@canonical.com \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=xemul@parallels.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).