Insecure use of temp files

Bug #642855 reported by Loïc Minier
282
This bug affects 3 people
Affects Status Importance Assigned to Milestone
flash-kernel (Ubuntu)
Fix Released
Medium
Unassigned
Lucid
Won't Fix
Medium
Unassigned
Natty
Won't Fix
Medium
Unassigned
Oneiric
Won't Fix
Medium
Unassigned
Precise
Won't Fix
Medium
Unassigned
Quantal
Fix Released
Medium
Unassigned

Bug Description

Binary package hint: flash-kernel

        Hi folks

While reviewing a recent patch in Debian #596889, I noticed that flash-kernel already had other instances of this apparently insecure construct:

> + tmp=$(tempfile)
> + cat $kfile >> $tmp
> + mkimage -A arm -O linux -T kernel -C none -a 0x60008000 \
> + -e 0x60008000 -n "Linaro Kernel" -d $tmp $tmp.uboot \
> + >&2 1>/dev/null

mkimage takes the kernel from $tmp and writes it to its first arg, $tmp.uboot. There is a window where an attacker can create a tmp.uboot symlink pointing to a file of his choice making this a probably low priority local denial of service vulnerability. Note that flash-kernel is called for each kernel upgrade and runs as root to install the new kernel.

I checked flash-kernel 1.6 and it doesn't call mkimage but is affected by a different type of tempfile abuse:

                tmp=$(tempfile)
                printf "Flashing kernel: " >&2
                (
                        sercomm_header $(expr $kfilesize + 16)
                        dd if=$kfile of=$tmp bs=$ksize1 count=1 2>/dev/null
                        nslu2_swap $tmp
                        sercomm_header 131072
                        dd if=$kfile of=$tmp ibs=$ksize1 skip=1 2>/dev/null
                        nslu2_swap $tmp
                        rm -f $tmp
                ) > "$kmtd" || error "failed."
                echo "done." >&2
                printf "Flashing initramfs: " >&2
                dd if=$ifile of=$tmp ibs=$(($imtdsize - 16)) conv=sync 2>/dev/null

Note how the tempfile is created, truncated by dd, truncated by dd a second time, removed, and then created again in this last dd call I quoted above.

   Cheers,

Kees Cook (kees)
Changed in flash-kernel (Ubuntu):
status: New → Confirmed
importance: Undecided → Low
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

This was fixed in 2.33 in Debian, but still not in Ubuntu. Since that is public, I am marking this bug as public.

Changed in flash-kernel (Ubuntu):
status: Confirmed → Triaged
visibility: private → public
Revision history for this message
Robie Basak (racb) wrote :

This isn't just a DoS. Isn't it a trojanable kernel? I put more detail as to why in bug #1003198 before I realised I was creating a dupe.

Revision history for this message
dann frazier (dannf) wrote : Re: [Bug 642855] Re: Insecure use of temp files

On Wed, May 23, 2012 at 12:55:38AM -0000, Robie Basak wrote:
> This isn't just a DoS. Isn't it a trojanable kernel? I put more detail
> as to why in bug #1003198 before I realised I was creating a dupe.

I think the in-kernel symlink protection limits the impact to a
DoS as long as your are running an Ubuntu kernel. See #959422.

Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

Replacing the destination file with a symlink would be blocked by the kernel, but creating an empty file would probably result in the kernel being trojanable.

This needs to be fixed. Best way would be to create a temp directory and work inside of it.

Changed in flash-kernel (Ubuntu):
importance: Low → Medium
Changed in flash-kernel (Ubuntu Lucid):
status: New → Confirmed
Changed in flash-kernel (Ubuntu Natty):
status: New → Confirmed
Changed in flash-kernel (Ubuntu Oneiric):
status: New → Confirmed
Changed in flash-kernel (Ubuntu Precise):
status: New → Confirmed
Changed in flash-kernel (Ubuntu Lucid):
importance: Undecided → Medium
Changed in flash-kernel (Ubuntu Natty):
importance: Undecided → Medium
Changed in flash-kernel (Ubuntu Oneiric):
importance: Undecided → Medium
Changed in flash-kernel (Ubuntu Precise):
importance: Undecided → Medium
Revision history for this message
Oliver Grawert (ogra) wrote :

i belive with the sync of version 3.0~rc4 from debian this is fixed for quantal

Changed in flash-kernel (Ubuntu Quantal):
status: Triaged → Fix Released
Changed in flash-kernel (Ubuntu Lucid):
assignee: nobody → Marc Deslauriers (mdeslaur)
Changed in flash-kernel (Ubuntu Natty):
assignee: nobody → Marc Deslauriers (mdeslaur)
Changed in flash-kernel (Ubuntu Oneiric):
assignee: nobody → Marc Deslauriers (mdeslaur)
Changed in flash-kernel (Ubuntu Precise):
assignee: nobody → Marc Deslauriers (mdeslaur)
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Thank you for reporting this bug to Ubuntu. natty has reached EOL
(End of Life) and is no longer supported. As a result, this bug
against natty is being marked "Won't Fix". Please see
https://wiki.ubuntu.com/Releases for currently supported Ubuntu
releases.

Please feel free to report any other bugs you may find.

Changed in flash-kernel (Ubuntu Natty):
status: Confirmed → Won't Fix
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Thank you for reporting this bug to Ubuntu. oneiric has reached EOL
(End of Life) and is no longer supported. As a result, this bug
against oneiric is being marked "Won't Fix". Please see
https://wiki.ubuntu.com/Releases for currently supported Ubuntu
releases.

Please feel free to report any other bugs you may find.

Changed in flash-kernel (Ubuntu Oneiric):
status: Confirmed → Won't Fix
Changed in flash-kernel (Ubuntu Lucid):
status: Confirmed → Won't Fix
assignee: Marc Deslauriers (mdeslaur) → nobody
Changed in flash-kernel (Ubuntu Natty):
assignee: Marc Deslauriers (mdeslaur) → nobody
Changed in flash-kernel (Ubuntu Oneiric):
assignee: Marc Deslauriers (mdeslaur) → nobody
Changed in flash-kernel (Ubuntu Precise):
assignee: Marc Deslauriers (mdeslaur) → nobody
Revision history for this message
Steve Langasek (vorlon) wrote :

The Precise Pangolin has reached end of life, so this bug will not be fixed for that release

Changed in flash-kernel (Ubuntu Precise):
status: Confirmed → Won't Fix
To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.