<?xml version="1.0" encoding="UTF-8" ?>

<bugzilla version="5.2"
          urlbase="https://bugzilla.altlinux.org/"
          
          maintainer="jenya@basealt.ru"
>

    <bug>
          <bug_id>20977</bug_id>
          
          <creation_ts>2009-08-06 19:48:29 +0400</creation_ts>
          <short_desc>Buffer overflow on volume access</short_desc>
          <delta_ts>2013-06-24 10:47:39 +0400</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Development</classification>
          <product>Sisyphus</product>
          <component>glusterfs</component>
          <version>unstable</version>
          <rep_platform>all</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Nikolay A. Fetisov">naf</reporter>
          <assigned_to name="Konstantin A Lepikhov (L.A. Kostis)">lakostis</assigned_to>
          <cc>kas</cc>
    
    <cc>lakostis</cc>
    
    <cc>lav</cc>
    
    <cc>ldv</cc>
          
          <qa_contact>qa-sisyphus</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>95815</commentid>
    <comment_count>0</comment_count>
    <who name="Nikolay A. Fetisov">naf</who>
    <bug_when>2009-08-06 19:48:29 +0400</bug_when>
    <thetext>В текущей версии 2.0.4-alt1.git20090715 при обращении к тому происходит переполнение буфера.
Система - текущий Sisyphus, проверялось на i586 и x86_64.

При обращении (ls) к смонтированному тому клиент glusterfs прекращает работу с сообщением:
-------8&lt;------
*** buffer overflow detected ***: glusterfs terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x40)[0xb7faef30]
/lib/libc.so.6[0xb7fad180]
/lib/libc.so.6(__strcpy_chk+0x44)[0xb7fac4f4]
/usr/lib/glusterfs/2.1.0git/xlator/protocol/client.so(client_lookup+0x1bd)[0xb7679a4d]
/usr/lib/glusterfs/2.1.0git/xlator/mount/fuse.so(fuse_root_lookup+0x179)[0xb7663149]
/usr/lib/glusterfs/2.1.0git/xlator/mount/fuse.so[0xb7663466]
/lib/libpthread.so.0[0xb8024480]
/lib/libc.so.6(clone+0x5e)[0xb7f9937e]
-------8&lt;------

Конфигурация сервера:

volume test-storage
  type storage/posix
  option directory /mnt/test
end-volume
volume test-server
  type protocol/server
  option transport-type tcp
  subvolumes test-storage
  option auth.addr.test-storage.allow 192.168.1.*
end-volume


Конфигурация клиента:

volume test
  type protocol/client
  option transport-type tcp
  option remote-host 192.168.1.254
  option remote-subvolume test-storage
end-volume

Предыдущая версия 2.0.1-alt1.git20090522 (на клиенте и сервере) работает, клиент 2.0.1 с сервером 2.0.4 не работает (не может смонтировать том),
клиент 2.0.4 с сервером 2.0.1 падает с вышеприведённым сообщением.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95818</commentid>
    <comment_count>1</comment_count>
    <who name="Konstantin A Lepikhov (L.A. Kostis)">lakostis</who>
    <bug_when>2009-08-06 22:53:42 +0400</bug_when>
    <thetext>А версии ядер и fuse на этих машинах одинаковые?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95839</commentid>
    <comment_count>2</comment_count>
    <who name="Nikolay A. Fetisov">naf</who>
    <bug_when>2009-08-07 12:26:54 +0400</bug_when>
    <thetext>(В ответ на комментарий №1)
&gt; А версии ядер и fuse на этих машинах одинаковые?

Везде fuse-2.7.3-alt3, glibc-core-2.10.1-alt4, ядро 2.6.27-ovz-smp-alt7.

При откате на 2.0.1-alt1.git20090522 обе пары (с x86_64 и с i586) работают нормально.

На машину с i586 могу дать доступ.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95920</commentid>
    <comment_count>3</comment_count>
    <who name="Konstantin A Lepikhov (L.A. Kostis)">lakostis</who>
    <bug_when>2009-08-08 13:34:12 +0400</bug_when>
    <thetext>да, похоже пока gluster в GIT сломан и придется откатываться на стабильный 2.0.4.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95969</commentid>
    <comment_count>4</comment_count>
    <who name="Konstantin A Lepikhov (L.A. Kostis)">lakostis</who>
    <bug_when>2009-08-09 16:58:33 +0400</bug_when>
    <thetext>(В ответ на комментарий №3)
&gt; да, похоже пока gluster в GIT сломан и придется откатываться на стабильный
&gt; 2.0.4.

http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=197 bug submitted to upstream.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96007</commentid>
    <comment_count>5</comment_count>
    <who name="Konstantin A Lepikhov (L.A. Kostis)">lakostis</who>
    <bug_when>2009-08-10 11:37:22 +0400</bug_when>
    <thetext>см. комментарий upstream&apos;а и http://osdir.com/ml/wine-patches/2009-07/msg00793.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96291</commentid>
    <comment_count>6</comment_count>
    <who name="Konstantin A Lepikhov (L.A. Kostis)">lakostis</who>
    <bug_when>2009-08-12 23:00:32 +0400</bug_when>
    <thetext>ping</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96297</commentid>
    <comment_count>7</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2009-08-13 02:03:29 +0400</bug_when>
    <thetext>Unless proven explicitly, I presume that gcc (which does boundary calculations) and glibc (which enables appropriate boundary checks via _FORTIFY_SOURCE switch) does their job properly, and aforementioned links confirm my suppose.

There are lot of projects with strcpy() calls which does buffer overflows recognized by glibc/gcc, either indeliberate or intended (see e.g. thread starting at http://lists.altlinux.org/pipermail/devel/2009-July/172997.html).

I have examples of intended buffer overflows (see e.g. http://lists.gnu.org/archive/html/bug-tar/2009-07/msg00001.html or http://cvsweb.openwall.com/cgi/cvsweb.cgi/Owl/packages/john/john/src/charset.c?r1=1.8#rev1.8), and I usually suggest to fix the code to avoid them instead of disabling boundary checks.

There are few cases (like gnupg, see http://lists.altlinux.org/pipermail/devel/2009-July/173072.html) where intended buffer overflows are not so easy to fix, though.

That is, I suggest to find the glusterfs code which results to buffer overflow detected by strcpy check, analize it and either fix the code or prove that gcc or glibc contains a bug in buffer boundary check.  In the unlikely second case, please reassign the bug back to glibc/gcc.

P.S. Please do not raise bug priority to critical value unless you really think that I should break my vacation and respond to the bug asap.  Thanx in advance.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96301</commentid>
    <comment_count>8</comment_count>
    <who name="Konstantin A Lepikhov (L.A. Kostis)">lakostis</who>
    <bug_when>2009-08-13 03:24:45 +0400</bug_when>
    <thetext>Dmitry,
Thanks for code samples, useful links and your patience. Have a nice vacation!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97478</commentid>
    <comment_count>9</comment_count>
    <who name="Repository Robot">repository-robot</who>
    <bug_when>2009-08-28 00:50:45 +0400</bug_when>
    <thetext>glusterfs-2.0.6-alt1.git20090817 -&gt; sisyphus:

* Thu Aug 27 2009 L.A. Kostis &lt;lakostis@altlinux&gt; 2.0.6-alt1.git20090817

- switch to GIT v2.0.6-13-g86f2f04.
- add hack to disable FORTIFY_SOURCE=2 optimisation due unpredictable
  logic in gcc (closes #20977).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103118</commentid>
    <comment_count>10</comment_count>
    <who name="Kirill A. Shutemov">kas</who>
    <bug_when>2009-11-14 03:15:37 +0300</bug_when>
    <thetext>In this case we definitely have false positive on strcpy().

typedef struct {
        uint64_t ino; /* NOTE: used only in case of &apos;root&apos; lookup */
        uint64_t par;
        uint32_t flags;
        uint32_t dictlen;
        char     path[0];
        char     bname[0];
        char     dict[0];
} __attribute__((packed)) gf_fop_lookup_req_t;

gluster tries to put NULL-terminated strings into field path and bname using strcpy() and put some data into dict using memcpy().

http://gcc.gnu.org/ml/gcc-patches/2009-06/msg00419.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103119</commentid>
    <comment_count>11</comment_count>
    <who name="Kirill A. Shutemov">kas</who>
    <bug_when>2009-11-14 03:32:11 +0300</bug_when>
    <thetext>&lt;Continue previous comment...&gt;

__builtin_object_size has been improved recently:
http://gcc.gnu.org/ml/gcc-patches/2009-06/msg00419.html

It&apos;s grate feature, but it gives false positive if we have more then one flexible array at the end of a structure. In this case we have three flexible array. It&apos;s quite tricky, but it&apos;s valid, I guess.

I think the best way to fix it in GCC.

As workaround you can use memcpy() instead strcpy(), but you have to review usage of all structures in gluster which have more than one flexible array.

Other workaround is -D_FORTIFY_SOURCE=1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103120</commentid>
    <comment_count>12</comment_count>
      <attachid>4061</attachid>
    <who name="Kirill A. Shutemov">kas</who>
    <bug_when>2009-11-14 03:33:44 +0300</bug_when>
    <thetext>Created attachment 4061
Reduced testcase</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103131</commentid>
    <comment_count>13</comment_count>
    <who name="Konstantin A Lepikhov (L.A. Kostis)">lakostis</who>
    <bug_when>2009-11-14 14:59:40 +0300</bug_when>
    <thetext>JFYI - glusterfs-2.0.8-alt1 в сизифе опять сломан из-за этой проблемы.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103132</commentid>
    <comment_count>14</comment_count>
    <who name="Kirill A. Shutemov">kas</who>
    <bug_when>2009-11-14 15:42:09 +0300</bug_when>
    <thetext>&gt; It&apos;s quite tricky, but it&apos;s valid, I guess.

According to C99 only the last element for struct can be a flexible array. See 6.7.2.1.16. But gluster use pre-C99 syntax for flexible arrays. Currently, I&apos;m not sure if GCC is right place to fix it.

One more link:
http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114834</commentid>
    <comment_count>15</comment_count>
    <who name="Kirill A. Shutemov">kas</who>
    <bug_when>2010-11-04 22:21:52 +0300</bug_when>
    <thetext>насколько я знаю, в апстриме glusterfs это пофиксили.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>141110</commentid>
    <comment_count>16</comment_count>
    <who name="Vitaly Lipatov">lav</who>
    <bug_when>2013-06-24 10:47:39 +0400</bug_when>
    <thetext>На текущей версии проблем не замечено.
glusterfs3-3.3.1-alt1</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>4061</attachid>
            <date>2009-11-14 03:33:44 +0300</date>
            <delta_ts>2009-11-14 03:33:44 +0300</delta_ts>
            <desc>Reduced testcase</desc>
            <filename>1.c</filename>
            <type>text/plain</type>
            <size>557</size>
            <attacher name="Kirill A. Shutemov">kas</attacher>
            
              <data encoding="base64">I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxzdGRpby5o
PgoKc3RydWN0IHRlc3QgewoJY2hhciBhMVswXTsKCWNoYXIgYTJbMF07Cn0gX19hdHRyaWJ1dGVf
XyAoKF9fcGFja2VkX18pKTsKCmludCBtYWluKGludCBhcmdjLCBjaGFyICoqYXJndikKewoJc3Ry
dWN0IHRlc3QgKnRlc3Q7CglpbnQgbGVuMSwgbGVuMjsKCglpZiAoYXJnYyA8IDMpCgkJcmV0dXJu
IDE7CgoJbGVuMSA9IHN0cmxlbihhcmd2WzFdKSArIDE7CglsZW4yID0gc3RybGVuKGFyZ3ZbMl0p
ICsgMTsKCgl0ZXN0ID0gbWFsbG9jKHNpemVvZigqdGVzdCkgKyBsZW4xICsgbGVuMik7CgojaWYg
MQoJc3RyY3B5KHRlc3QtPmExLCBhcmd2WzFdKTsKCXN0cmNweSh0ZXN0LT5hMiArIGxlbjEsIGFy
Z3ZbMl0pOwojZWxzZQoJbWVtY3B5KHRlc3QtPmExLCBhcmd2WzFdLCBsZW4xKTsKCW1lbWNweSh0
ZXN0LT5hMiArIGxlbjEsIGFyZ3ZbMl0sIGxlbjIpOwojZW5kaWYKCglwcmludGYoIiVzOiVzXG4i
LCB0ZXN0LT5hMSwgdGVzdC0+YTIgKyBsZW4xKTsKCglyZXR1cm4gMDsKfQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>