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  linux-cve-announce  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]
Message-ID: <4570F373.5090608@kaigai.gr.jp>
Date:	Sat, 02 Dec 2006 12:30:59 +0900
From:	KaiGai Kohei <kaigai@...gai.gr.jp>
To:	"Serge E. Hallyn" <serue@...ibm.com>
CC:	Bill O'Donnell <billodo@....com>,
	Chris Friedhoff <chris@...edhoff.org>,
	Andrew Morton <akpm@...l.org>, linux-kernel@...r.kernel.org,
	linux-security-module@...r.kernel.org,
	Stephen Smalley <sds@...ho.nsa.gov>,
	James Morris <jmorris@...ei.org>,
	Chris Wright <chrisw@...s-sol.org>,
	Alexey Dobriyan <adobriyan@...il.com>
Subject: Re: [PATCH] Implement file posix capabilities

Oops, it's my stupid bug.

> Ah, this actually makes sense.  The setfcaps usage() statement does
> 
> 	for (i=0; _cap_names[i]; i++) {
> 		printf...
> 
> so it expects _cap_names to end with a terminating NULL, but that
> doesn't seem to be the case in cap_names.h in libcap.
> 
> KaiGai, perhaps setfcaps should do something like
> 
> diff setfcaps.c.orig setfcaps.c
> 25c25
> <     for (i=0; _cap_names[i]; i++)
> ---
>>     for (i=0; i<__CAP_BITS; i++)

I fixed the matter as follows:

[kaigai@...u libcap-1.10.kg]$ env LANG=C svn diff -r2:3
Index: libcap/_makenames.c
===================================================================
--- libcap/_makenames.c (revision 2)
+++ libcap/_makenames.c (revision 3)
@@ -45,6 +45,7 @@
            "#define __CAP_BITS   %d\n"
            "\n"
            "#ifdef LIBCAP_PLEASE_INCLUDE_ARRAY\n"
+          "  int const _cap_names_num = __CAP_BITS;\n"
            "  char const *_cap_names[__CAP_BITS] = {\n", maxcaps);

      for (i=0; i<maxcaps; ++i) {
Index: libcap/include/sys/capability.h
===================================================================
--- libcap/include/sys/capability.h     (revision 2)
+++ libcap/include/sys/capability.h     (revision 3)
@@ -113,6 +113,7 @@
  extern int capgetp(pid_t pid, cap_t cap_d);
  extern int capsetp(pid_t pid, cap_t cap_d);
  extern char const *_cap_names[];
+extern int const _cap_names_num;

  #endif /* !defined(_POSIX_SOURCE) */

Index: progs/setfcaps.c
===================================================================
--- progs/setfcaps.c    (revision 2)
+++ progs/setfcaps.c    (revision 3)
@@ -14,6 +14,7 @@
  #include <errno.h>
  #include <sys/capability.h>

+extern int const _cap_names_num;
  extern char const *_cap_names[];

  static void usage() {
@@ -21,8 +22,8 @@
      int i;

      fputs(message, stderr);
-    for (i=0; _cap_names[i]; i++)
-       fprintf(stderr, "%s%s", i%4==0 ? "\n\t" : ", ", _cap_names[i]);
+    for (i=0; i < _cap_names_num; i++)
+        fprintf(stderr, "%s%s", i%4==0 ? "\n\t" : ", ", _cap_names[i]);
      fputc('\n', stderr);
      exit(0);
  }
[kaigai@...u libcap-1.10.kg]$

Because '__CAP_BITS' is decided at compiling time, I think it's not
appropriate to indicate the length of _cap_names[] which is linked
at run time.
Therefore, I add a new integer variable _cap_names_num to represent
the length of _cap_names at run time.

You can download it from http://www.kaigai.gr.jp/index.php?FrontPage#b556e50d

Thanks,
-- 
KaiGai Kohei <kaigai@...gai.gr.jp>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ