<!-- 
RSS generated by JIRA (9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c) at Sat Feb 10 01:20:15 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-1853] &apos;out-of-bounds access&apos; error in osd_scrub_setup()</title>
                <link>https://jira.whamcloud.com/browse/LU-1853</link>
                <project id="10000" key="LU">Lustre</project>
                    <description>&lt;p&gt;In osd_scrub_setup(), id variable is of type &apos;struct osd_inode_id *&apos; (size 8). But then this variable is passed to __osd_oi_lookup(), and in this function, it is passed to osd_oi_iam_lookup(), which casts it to a &apos;struct dt_rec *&apos;. Then it is passed to osd_fid_unpack() by casting it to &apos;struct lu_fid *&apos;. And at last, inside this function, a memcpy() is performed considering the variable is of type &apos;struct lu_fid *&apos;, which is of size 16.&lt;br/&gt;
So we are accessing memory beyond what was allocated for that variable.&lt;/p&gt;

&lt;p&gt;I do not know how to fix this issue, as it is quite complex.&lt;/p&gt;</description>
                <environment></environment>
        <key id="15731">LU-1853</key>
            <summary>&apos;out-of-bounds access&apos; error in osd_scrub_setup()</summary>
                <type id="7" iconUrl="https://jira.whamcloud.com/images/icons/issuetypes/task_agile.png">Technical task</type>
                            <parent id="17451">LU-2753</parent>
                                    <priority id="3" iconUrl="https://jira.whamcloud.com/images/icons/priorities/major.svg">Major</priority>
                        <status id="5" iconUrl="https://jira.whamcloud.com/images/icons/statuses/resolved.png" description="A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.">Resolved</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="2">Won&apos;t Fix</resolution>
                                        <assignee username="yong.fan">nasf</assignee>
                                    <reporter username="sebastien.buisson">Sebastien Buisson</reporter>
                        <labels>
                            <label>build</label>
                            <label>coverity</label>
                    </labels>
                <created>Fri, 7 Sep 2012 04:07:49 +0000</created>
                <updated>Fri, 4 Oct 2013 19:59:11 +0000</updated>
                            <resolved>Fri, 19 Oct 2012 02:25:24 +0000</resolved>
                                    <version>Lustre 2.4.0</version>
                                                        <due></due>
                            <votes>0</votes>
                                    <watches>6</watches>
                                                                            <comments>
                            <comment id="44380" author="adilger" created="Fri, 7 Sep 2012 16:39:24 +0000"  >&lt;p&gt;This bug is in the OI Scrub code, but I think there is also a problem with the API itself that allows this kind of problem to be introduced.&lt;/p&gt;

&lt;p&gt;Firstly, the requirement to always cast to &lt;tt&gt;(struct dt_key *)&lt;/tt&gt; means that any compiler type checking is disabled, and there is no way for the compiler or lower layers of the code to detect whether the caller is passing the correct pointer for the underlying index.  It would be much safer if struct dt_key were a real structure like:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;struct dt_key {
        void   *dtk_key;
        &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;     dtk_len;
};
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;so that the key size is passed up and down the whole stack.  This would also avoid the need to cast arguments everywhere (which in itself is evil) since that breaks the ability of the compiler to check the code correctness.  Instead, the caller would allocate a dt_key on the stack, assign the key pointer to dtk_key, and the length to dtk_len, and the parameter type to the function would be correct.&lt;/p&gt;

&lt;p&gt;It&apos;s 8 more bytes on the stack at the top-level calling function, but infinitely more robustness inside the code.  I don&apos;t know if there is some value to including an &quot;int dtk_type&quot; field as well, since the caller &lt;em&gt;should&lt;/em&gt; know what type of index is being accessed, but it is an idea that crossed my mind and there are 4 free bytes in the struct that would otherwise go unused.&lt;/p&gt;</comment>
                            <comment id="44382" author="adilger" created="Fri, 7 Sep 2012 16:44:34 +0000"  >&lt;p&gt;Another potential issue is that even after the code to accept a proper struct dt_key, this code will need close examination to ensure that all existing callers actually pass a proper dt_key instead of the current practice of typecasting.  It probably makes sense to use a slightly different name for the structure, so that in-flight patches will get a compiler warning if they are still using the old practice of &quot;(struct dt_key *)&amp;amp;key&quot; instead of filling in the key properly:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;struct dt_keylen {
        void   *dtk_key;
        &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;     dtk_len;
};
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or possibly a better name than &quot;dt_keylen&quot; could be found.&lt;/p&gt;</comment>
                            <comment id="46169" author="yong.fan" created="Mon, 8 Oct 2012 11:01:25 +0000"  >&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt; osd_oi_iam_lookup(struct osd_thread_info *oti,
                             struct osd_oi *oi, struct dt_rec *rec,
                             &lt;span class=&quot;code-keyword&quot;&gt;const&lt;/span&gt; struct dt_key *key)
{
...
        rc = iam_it_get(it, (struct iam_key *)key);
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (rc &amp;gt;= 0) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (S_ISDIR(oi-&amp;gt;oi_inode-&amp;gt;i_mode))
                        iam_rec = (struct iam_rec *)oti-&amp;gt;oti_ldp;
                &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt;
                        iam_rec = (struct iam_rec *)rec;
                
                iam_reccpy(&amp;amp;it-&amp;gt;ii_path.ip_leaf, (struct iam_rec *)iam_rec);
===&amp;gt;                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (S_ISDIR(oi-&amp;gt;oi_inode-&amp;gt;i_mode))
                        osd_fid_unpack((struct lu_fid *)rec,
                                       (struct osd_fid_pack *)iam_rec);
        }               
...
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this case, the IAM container is an OI index file, which is NOT directory, so the branch for &quot;if (S_ISDIR(oi-&amp;gt;oi_inode-&amp;gt;i_mode))&quot; in above code section will be skipped for the call trace: osd_scrub_setup() =&amp;gt; __osd_oi_lookup() =&amp;gt; osd_oi_iam_lookup(). So the OI scrub should not trigger &quot;out-of-bounds access&quot; error.&lt;/p&gt;


&lt;p&gt;Sebastien, have you hit such failure during any test? or thought there may be potential issues by analyzing code?&lt;/p&gt;</comment>
                            <comment id="46333" author="sebastien.buisson" created="Wed, 10 Oct 2012 10:33:56 +0000"  >&lt;p&gt;Hi Yong Fan,&lt;/p&gt;

&lt;p&gt;This issue was found by the static code analysis tool named Coverity.&lt;/p&gt;

&lt;p&gt;According to your analysis, osd_fid_unpack() will not be called because the condition above will evaluate to false. But maybe there is another call path leading to the issue described here?&lt;/p&gt;

&lt;p&gt;Sebastien.&lt;/p&gt;</comment>
                            <comment id="46358" author="yong.fan" created="Wed, 10 Oct 2012 22:55:08 +0000"  >&lt;p&gt;Originally, the IAM was designed not only for index file, such as OI files, and quota files, but also for storing directory under Lustre namespace. But the later use case is not valid since Lustre-2.0, that means the &quot;if (S_ISDIR(oi-&amp;gt;oi_inode-&amp;gt;i_mode))&quot; branch will not be trigger anymore in current 2.x code. So I think there will not be out-of-bounds&quot; issues in IAM according to current use cases.&lt;/p&gt;</comment>
                            <comment id="46364" author="sebastien.buisson" created="Thu, 11 Oct 2012 02:54:20 +0000"  >&lt;p&gt;OK I understand.&lt;br/&gt;
So maybe in that case, it would be better to remove this &apos;dead&apos; branch, right?&lt;/p&gt;</comment>
                            <comment id="46416" author="yong.fan" created="Thu, 11 Oct 2012 21:33:32 +0000"  >&lt;p&gt;Yes, there are some dead codes in IAM, not only for this, but also for LVAR part. But nobody knows whether they will be re-used in the future or not, so these codes keep there since the beginning.&lt;/p&gt;</comment>
                            <comment id="46766" author="yong.fan" created="Fri, 19 Oct 2012 02:25:24 +0000"  >&lt;p&gt;It will not cause issues under current use mode.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </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_10390" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hzvgkn:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10090" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>6334</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                </customfields>
    </item>
</channel>
</rss>