<!-- 
RSS generated by JIRA (9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c) at Sat Feb 10 02:20:49 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>Whamcloud Community JIRA</title>
    <link>https://jira.whamcloud.com</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.4.14</version>
        <build-number>940014</build-number>
        <build-date>05-12-2023</build-date>
    </build-info>


<item>
            <title>[LU-8819] lprocfs_alloc_stats() Segmentation fault (core dumped)</title>
                <link>https://jira.whamcloud.com/browse/LU-8819</link>
                <project id="10000" key="LU">Lustre</project>
                    <description>&lt;p&gt;In lustre/obdclass/lprocfs_status.c ,and in the function &quot;lprocfs_alloc_stats&quot;,&lt;br/&gt;
when alloc percpu pointers for all possible cpu slots,the  corresponding code:&lt;br/&gt;
LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu&lt;span class=&quot;error&quot;&gt;&amp;#91;num_entry&amp;#93;&lt;/span&gt;));&lt;br/&gt;
In fact ,this code didn&apos;t alloc space for its member struct lprocfs_counter lp_cntr&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;,&lt;br/&gt;
but in other operations like funcion&#65306;&lt;br/&gt;
 lprocfs_counter_init which call lprocfs_stats_counter_get&lt;br/&gt;
 the code in fuction  lprocfs_stats_counter_get such as &lt;br/&gt;
 stats-&amp;gt;ls_percpu&lt;span class=&quot;error&quot;&gt;&amp;#91;cpuid&amp;#93;&lt;/span&gt;-&amp;gt;lp_cntr&lt;span class=&quot;error&quot;&gt;&amp;#91;index&amp;#93;&lt;/span&gt; &lt;br/&gt;
 may access memory that not belong to var stats itself,&lt;br/&gt;
 it&apos;s not safe and may lead to Segmentation fault.especially when there is not enough memory.&lt;/p&gt;</description>
                <environment>lustre 2.8.0 centos7 kernel-3.10.0_3.10.0_327.3.1.el7_lustre.x86_64-1.x86_64</environment>
        <key id="41459">LU-8819</key>
            <summary>lprocfs_alloc_stats() Segmentation fault (core dumped)</summary>
                <type id="1" iconUrl="https://jira.whamcloud.com/secure/viewavatar?size=xsmall&amp;avatarId=11303&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.whamcloud.com/images/icons/priorities/minor.svg">Minor</priority>
                        <status id="1" iconUrl="https://jira.whamcloud.com/images/icons/statuses/open.png" description="The issue is open and ready for the assignee to start work on it.">Open</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="laisiyao">Lai Siyao</assignee>
                                    <reporter username="&#37011;&#20181;&#20891;">ShijunDeng</reporter>
                        <labels>
                            <label>lprocfs</label>
                    </labels>
                <created>Thu, 10 Nov 2016 12:17:35 +0000</created>
                <updated>Tue, 14 Mar 2017 17:34:57 +0000</updated>
                                            <version>Lustre 2.8.0</version>
                                                        <due></due>
                            <votes>0</votes>
                                    <watches>6</watches>
                                                                            <comments>
                            <comment id="173171" author="pjones" created="Thu, 10 Nov 2016 18:57:24 +0000"  >&lt;p&gt;Lai&lt;/p&gt;

&lt;p&gt;Could you please advise on this issue?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

&lt;p&gt;Peter&lt;/p&gt;</comment>
                            <comment id="173173" author="jhammond" created="Thu, 10 Nov 2016 19:05:45 +0000"  >&lt;p&gt;&lt;tt&gt;lprocfs_stats_counter_get()&lt;/tt&gt; is only used after successful calls to &lt;tt&gt;lprocfs_stats_lock()&lt;/tt&gt; or checks that &lt;tt&gt;stats-&amp;gt;ls_percpu&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;&lt;/tt&gt; is not NULL.&lt;/p&gt;</comment>
                            <comment id="173257" author="&#37011;&#20181;&#20891;" created="Fri, 11 Nov 2016 03:02:03 +0000"  >&lt;p&gt;struct lprocfs_counter {&lt;br/&gt;
	__s64	lc_count;&lt;br/&gt;
	__s64	lc_min;&lt;br/&gt;
	__s64	lc_max;&lt;br/&gt;
	__s64	lc_sumsquare;&lt;br/&gt;
	/*&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Every counter has lc_array_sum&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;, while lc_array_sum&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt; is only&lt;/li&gt;
	&lt;li&gt;for irq context counter, i.e. stats with&lt;/li&gt;
	&lt;li&gt;LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need&lt;/li&gt;
	&lt;li&gt;lc_array_sum&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt;&lt;br/&gt;
	 */&lt;br/&gt;
	__s64	lc_array_sum&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt;;&lt;br/&gt;
};&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;struct lprocfs_percpu {&lt;br/&gt;
	struct lprocfs_counter lp_cntr&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;;&lt;br/&gt;
};&lt;/p&gt;


&lt;p&gt;struct lprocfs_stats {&lt;br/&gt;
	/* # of counters */&lt;br/&gt;
	unsigned short			ls_num;&lt;br/&gt;
	/* 1 + the biggest cpu # whose ls_percpu slot has been allocated */&lt;br/&gt;
	unsigned short			ls_biggest_alloc_num;&lt;br/&gt;
	enum lprocfs_stats_flags	ls_flags;&lt;br/&gt;
	/* Lock used when there are no percpu stats areas; For percpu stats,&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;it is used to protect ls_biggest_alloc_num change */&lt;br/&gt;
	spinlock_t			ls_lock;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;	/* has ls_num of counter headers */&lt;br/&gt;
	struct lprocfs_counter_header	*ls_cnt_header;&lt;br/&gt;
	struct lprocfs_percpu		*ls_percpu&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;;&lt;br/&gt;
};&lt;/p&gt;

&lt;p&gt;the above code is corresponding definition,In lustre/obdclass/lprocfs_status.c ,and in the function &quot;lprocfs_alloc_stats&quot;,&lt;br/&gt;
when alloc percpu pointers for all possible cpu slots,the corresponding code:&lt;br/&gt;
LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu&lt;span class=&quot;error&quot;&gt;&amp;#91;num_entry&amp;#93;&lt;/span&gt;));&lt;/p&gt;

&lt;p&gt;the access to stats-&amp;gt;ls_percpu&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;  is safe,but it&apos;s not safe to acccess lp_cntr&lt;span class=&quot;error&quot;&gt;&amp;#91;index&amp;#93;&lt;/span&gt;,to simplify the analysis  for the problem,I will justify my position by giving one example as follow&#65306;&lt;/p&gt;

&lt;p&gt;#include&amp;lt;stdio.h&amp;gt;&lt;br/&gt;
struct en{&lt;br/&gt;
    int a;&lt;br/&gt;
    int b;&lt;br/&gt;
    int c&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;;&lt;br/&gt;
};&lt;/p&gt;


&lt;p&gt;int main(){&lt;/p&gt;

&lt;p&gt;    struct en e;&lt;br/&gt;
    e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;=1000;&lt;br/&gt;
    e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt;=2000;&lt;br/&gt;
    e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;2&amp;#93;&lt;/span&gt;=3000;&lt;br/&gt;
    e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;1000&amp;#93;&lt;/span&gt;=3000;&lt;br/&gt;
    printf(&quot;e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;=%d\n&quot;,e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;);&lt;br/&gt;
    printf(&quot;e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt;=%d\n&quot;,e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt;);&lt;br/&gt;
    printf(&quot;e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;2&amp;#93;&lt;/span&gt;=%d\n&quot;,e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;2&amp;#93;&lt;/span&gt;);&lt;br/&gt;
    printf(&quot;e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;1000&amp;#93;&lt;/span&gt;=%d\n&quot;,e.c&lt;span class=&quot;error&quot;&gt;&amp;#91;1000&amp;#93;&lt;/span&gt;);&lt;br/&gt;
    return 0;&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;the small demo can run correctly,sometimes.but it&apos;s not safe.For the same reson,&lt;br/&gt;
The code in lustre2.8.0 such as cntr = &amp;amp;stats-&amp;gt;ls_percpu&lt;span class=&quot;error&quot;&gt;&amp;#91;cpuid&amp;#93;&lt;/span&gt;-&amp;gt;lp_cntr&lt;span class=&quot;error&quot;&gt;&amp;#91;index&amp;#93;&lt;/span&gt; isn&apos;t safe,too.&lt;br/&gt;
Possibly because the value of index is small(it&apos;s cannot  up to 100,not to 1000),the error &quot;Segmentation fault (core dumped)&quot; occurs rarely.&lt;/p&gt;
</comment>
                            <comment id="173434" author="laisiyao" created="Mon, 14 Nov 2016 03:31:14 +0000"  >&lt;p&gt;Did you really meet segfault? If so, can you post logs or backtraces?&lt;/p&gt;

&lt;p&gt;I verified the code&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;does allocate percpu data, and can be accessed successfully.&lt;/p&gt;

&lt;p&gt;While your example code is different from above code, if you change to below:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;
struct en
{ int a; int b; int c[0]; }
;
int main()
{
 struct en *e = malloc(offset(struct en, c[1001]);

 e-&amp;gt;c[0]=1000;
 e-&amp;gt;c[1]=2000;
 e-&amp;gt;c[2]=3000;
 e-&amp;gt;c[1000]=3000;
 printf(&quot;e.c[0]=%d\n&quot;,e-&amp;gt;c[0]);
 printf(&quot;e.c[1]=%d\n&quot;,e-&amp;gt;c[1]);
 printf(&quot;e.c[2]=%d\n&quot;,e-&amp;gt;c[2]);
 printf(&quot;e.c[1000]=%d\n&quot;,e-&amp;gt;c[1000]);
 return 0;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It should always work, could you take a try?&lt;/p&gt;
</comment>
                            <comment id="176407" author="gerrit" created="Sun, 4 Dec 2016 14:47:52 +0000"  >&lt;p&gt;please ignore.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="24048" name="QQ&#25130;&#22270;20161110201410.png" size="21879" author="&#37011;&#20181;&#20891;" created="Thu, 10 Nov 2016 12:17:35 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                            <customfield id="customfield_10890" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10040" key="com.atlassian.jira.plugin.system.customfieldtypes:labels">
                        <customfieldname>Epic</customfieldname>
                        <customfieldvalues>
                                        <label>interoperability</label>
    
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10030" key="com.atlassian.jira.plugin.system.customfieldtypes:labels">
                        <customfieldname>Epic/Theme</customfieldname>
                        <customfieldvalues>
                                        <label>Lustre-2.8.0</label>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10070" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Project</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10032"><![CDATA[Test Infrastructure]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10390" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hzyv5j:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10090" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10060" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Severity</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10023"><![CDATA[4]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                        </customfields>
    </item>
</channel>
</rss>