On Tue, Oct 25, 2016 at 12:48 AM, Valentin B <[log in to unmask]> wrote:
> Hi Akemi,
>
> The fix allows me to run the cow vulnerability but it blocks which is good.
>
> See the following:
>
> DirtyCow root privilege escalation
> Backing up /usr/bin/passwd to /tmp/bak
> Size of binary: 27832
> Racing, this may take a while..
> thread stopped
> thread stopped
(snip)
> So my question is, what has been exactly patched to the recently upstream
> kernel.
Thanks for the detailed note.
Because the source code is available, I did a diff between kernels
3.10.0-327.36.2.el7 and 3.10.0-327.36.3.el7 and am attaching it for
anyone to see.
Akemi
diff -uNpr linux-3.10.0-327.36.2.el7/include/linux/mm.h linux-3.10.0-327.36.3.el7/include/linux/mm.h
--- linux-3.10.0-327.36.2.el7/include/linux/mm.h 2016-09-27 11:19:17.000000000 -0700
+++ linux-3.10.0-327.36.3.el7/include/linux/mm.h 2016-10-19 23:43:21.000000000 -0700
@@ -1971,6 +1971,7 @@ static inline struct page *follow_page(s
#define FOLL_NUMA 0x200 /* force NUMA hinting page fault */
#define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */
#define FOLL_TRIED 0x800 /* a retry, previous pass started an IO */
+#define FOLL_COW 0x4000 /* internal GUP flag */
typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
void *data);
diff -uNpr linux-3.10.0-327.36.2.el7/Makefile linux-3.10.0-327.36.3.el7/Makefile
--- linux-3.10.0-327.36.2.el7/Makefile 2016-09-27 11:19:17.000000000 -0700
+++ linux-3.10.0-327.36.3.el7/Makefile 2016-10-19 23:43:21.000000000 -0700
@@ -5,7 +5,7 @@ EXTRAVERSION =
NAME = Unicycling Gorilla
RHEL_MAJOR = 7
RHEL_MINOR = 2
-RHEL_RELEASE = 327.36.2
+RHEL_RELEASE = 327.36.3
RHEL_DRM_VERSION = 4
RHEL_DRM_PATCHLEVEL = 1
RHEL_DRM_SUBLEVEL = 0
diff -uNpr linux-3.10.0-327.36.2.el7/mm/memory.c linux-3.10.0-327.36.3.el7/mm/memory.c
--- linux-3.10.0-327.36.2.el7/mm/memory.c 2016-09-27 11:19:17.000000000 -0700
+++ linux-3.10.0-327.36.3.el7/mm/memory.c 2016-10-19 23:43:21.000000000 -0700
@@ -131,6 +131,15 @@ static int __init init_zero_pfn(void)
}
core_initcall(init_zero_pfn);
+/*
+ * FOLL_FORCE can write to even unwritable pte's, but only
+ * after we've gone through a COW cycle and they are dirty.
+ */
+static inline bool can_follow_write_pte(pte_t pte, unsigned int flags)
+{
+ return pte_write(pte) ||
+ ((flags & FOLL_FORCE) && (flags & FOLL_COW) && pte_dirty(pte));
+}
#if defined(SPLIT_RSS_COUNTING)
@@ -1588,7 +1597,7 @@ split_fallthrough:
}
if ((flags & FOLL_NUMA) && pte_numa(pte))
goto no_page;
- if ((flags & FOLL_WRITE) && !pte_write(pte))
+ if ((flags & FOLL_WRITE) && !can_follow_write_pte(pte, flags))
goto unlock;
page = vm_normal_page(vma, address, pte);
@@ -1900,7 +1909,7 @@ long __get_user_pages(struct task_struct
*/
if ((ret & VM_FAULT_WRITE) &&
!(vma->vm_flags & VM_WRITE))
- foll_flags &= ~FOLL_WRITE;
+ foll_flags |= FOLL_COW;
cond_resched();
}
|