Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3790837imm; Mon, 2 Jul 2018 05:45:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcdtAnjwa+JUZ1DJua4C7XSgFfblTF360DczjZSZnr5wkAcHHOmrqltbaTHNRGqBnnTXLpN X-Received: by 2002:a62:990f:: with SMTP id d15-v6mr11199226pfe.162.1530535544080; Mon, 02 Jul 2018 05:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530535544; cv=none; d=google.com; s=arc-20160816; b=KztuJIdUpS4XcRpXBj7W/u+EL98otfRj08K7uTJX//jjBWn9V+BSL6nnqKr0bMGASr AtwptlSk/8lK+q/w/PFRz9peiBXJKI+p4nnuNc7VNaYoYZlNi041aWLtIfN4q2fgwZp4 T+2v7WjqVbs1q8LquZGq+SIlHj2isurYPvp1O+GJLxMS9PD4hZcQn22GCLaWdXztcjCc fDZyzdMYb0soPkT5pvoZ4c6CetNRpfttH3tRYYv9hLu/3vzEv55IYDPJesxsYJzKJIU/ ECw+/nLfiYLBXHzqZKuQupLnWfmOCRKvzgZW9/ywG+oJCAdH5TbyMjz1JONBTY9qM2br iK9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature:arc-authentication-results; bh=RxrMUVGDhR3GC/B2L1wpEqprgsmh4736CIMcI8Fd+JY=; b=jI3Zv5TouN+eK+WIslJaF3QYWg4xkrCYmxMSM8ZKh0PCOYkbgrLgrzIYqbL7fAMhK7 eATxPuaULldmscsEhqTEq1lNhQp7YoZaIsY2XHfTTSrLddMl2srVWnTo/5IZO+/BLkwY X7n8Tymwa1vM1PUIKeUKflx4q8IjfZoL4XtId3xPnHJMn/qVLBV4AHQGveCOVzIaE7Jq iVG0+ywJJZGFAaqLKjd4j+hvxeAlFYu/RFyeETQajsnNrYG7wfbQXQJAdu0fPwFNZjfJ PKsMlN2X7eah++60xspawqzY38BZs3tYercx63rscNSzIekjfUl7RZHm6NNykf1PmOzu r6Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=suQygYhm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11-v6si2868249pfe.102.2018.07.02.05.45.29; Mon, 02 Jul 2018 05:45:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=suQygYhm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754475AbeGBLzz (ORCPT + 99 others); Mon, 2 Jul 2018 07:55:55 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:40270 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753397AbeGBLzx (ORCPT ); Mon, 2 Jul 2018 07:55:53 -0400 Received: by mail-ed1-f66.google.com with SMTP id e19-v6so689243edq.7; Mon, 02 Jul 2018 04:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=RxrMUVGDhR3GC/B2L1wpEqprgsmh4736CIMcI8Fd+JY=; b=suQygYhmdUbAbSLIKmnvlMSGhIJlzcE7JZtjccKnu1XZlPDJXWK6mJCDOV8xsLBG4C C0OxCNww1FmbynVzv04QwXBPnYWs+jfdyt8lA+Fg3hyshwuFOJnhkV/kdCwaT9BVdOee 3vtTgB/0fXUe2WPoCX3Dz7Z2woXOv73kSH+YuoJnImnX7KCwGwjDdXtD2sPRyhmU1V5+ csMN6GDiOSXP3VocqK/JUU+lXxMc/0fG9Zw0wkVJ41MNCYWbXOtLrTuybMFs4NPYM2A4 qNpLKFn1IGZ/sf87O4lqRSck61WOkVV3qWxzpUYLY5D9L+0qeWwb6DOQtZIb7Hiw76rd AUtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=RxrMUVGDhR3GC/B2L1wpEqprgsmh4736CIMcI8Fd+JY=; b=Ihey03P4rbko29VDD0SMhlHU93aQCb1xEUHfxT6NoPk9Bovowyaj/XprCnx8EHhFc9 E8anXiS5ao84iFKCbRskvf3dtARzcpN2CT72+14g3jD9aZOA2P8eHjo/sL5ybb00wFn9 PrlJwnaEEMw326zDAhqwr5YHzGm8NZhyTLBBGjgrx4fAhKwLRBvUc+910IAEu+j9oNwQ VIWOJux/o+t62ocd9j3B8em6wmQmUQ/GDGNHBRn/arl7aLm9dX/ZL1UD3tYEnVAl2Gd2 r8pTG21VgtSj5Md+XqutoMXY5RTLooL5vsKb4wQhZfnzNf2uek0mTBJr8wrTyTG4O2xs SBnw== X-Gm-Message-State: APt69E0vEsMsb1GQtEsmjGJLyP/Oo7q525OAKXZW4R+WAy4bXJVmFZNT oopJFOxjEiVZr7q/ybXF3rXxAErz X-Received: by 2002:a50:d9c7:: with SMTP id x7-v6mr23865751edj.95.1530532551362; Mon, 02 Jul 2018 04:55:51 -0700 (PDT) Received: from [192.168.42.231] (pd-18-120-80.service.infuturo.it. [151.18.120.80]) by smtp.gmail.com with ESMTPSA id s21-v6sm7237537edr.62.2018.07.02.04.55.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jul 2018 04:55:50 -0700 (PDT) Subject: Re: [PATCH upstream] KASAN: slab-out-of-bounds Read in getname_kernel To: Ian Kent Cc: linux-kernel@vger.kernel.org, syzkaller@googlegroups.com, autofs@vger.kernel.org References: <38c5a8ad-c192-74b9-b2ff-9eb2a3386930@gmail.com> <1530493827.2749.8.camel@themaw.net> <1530495726.2749.13.camel@themaw.net> <1bbf3634-6c2a-f40e-a9d3-9d6ffc9a0562@gmail.com> <1530526820.9527.4.camel@themaw.net> From: tomas Openpgp: preference=signencrypt Autocrypt: addr=tomasbortoli@gmail.com; prefer-encrypt=mutual; keydata= xsFNBFpCTZMBEADNZ1+Ibh0Z4pgGRcd1aOUMbe/YfHktmajjcoTnKmZZunjoUVAl8waeLITd BC2c8i1wHzHcnthrmb1izs5XlG6PZnl8n5tjysSNbwggzS1NcEK1qgn5VjNlHQ5aRMUwCC51 kicBiNmlQk2UuzzWwdheRGnaf+O1MNhC0GBeEDKQAL5obOU92pzflv6wWNACr+lHxdnpyies mOnRMjH16NjuTkrGbEmJe+MKp0qbjvR3R/dmFC1wczniRMQmV5w3MZ/N9wRappE+Atc1fOM+ wP7AWNuPvrKg4bN5uqKZLDFH7OFpxvjgVdWM40n0cQfqElWY9as+228Sltdd1XyHtUWRF2VW O1l5L0kX0+7+B5k/fpLhXqD3Z7DK7wRXpXmY59pofk7aFdcN97ZK+r6R7mqrwX4W9IpsPhkT kUyg3/Dx/khBZlJKFoUP325/hoH684bSiPEBroel9alB7gTq2ueoFwy6R3q5CMUw3D+CZWHA 3xllu46TRQ/Vt2g0cIHQNPoye2OWYFJ6kSEvaLpymjNDJ9ph2EuHegonDfOaYSq34ic2BcdB JkCgXRLP5K7KtRNJq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I/zegeblInnLi08Gq6mT6RkD6wV9HE5U3 EIU0rDPyJo54MW39wGjfC2+PM5I0xebbxtnuTewRchVVfm7UWgLAy11pV3xM4wMSJOuqVMOz jYpWKYxDTpvsZ0ginUUY993Gb8k/CxjABEMUGVHhQPZ0OzjHIKS6cTzN6ue8bB+CGOLCaQp1 C0NRT5Tn9zpLxtf5nBExFd/zVENY5vAV2ZbKQdemO54O7j6B9DSgVRrm83GCZxbL4d+qTYBF 3tSCWw/6SG1F3q9gR9QrSC2YRjCmhijUVEh6FhZwB58TNZ1sEEttrps8TDa5tUd9 Message-ID: Date: Mon, 2 Jul 2018 13:55:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <1530526820.9527.4.camel@themaw.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Yes, thanks. Please use my full name, Tomas Bortoli. Cheers On 07/02/2018 12:20 PM, Ian Kent wrote: > On Mon, 2018-07-02 at 10:31 +0200, tomas wrote: >> Hi Ian, >> >> you are welcome! >> >> yes your patch is much better. You should just put the "_IOC_NR" macro >> around "cmd" in the lines added to "validate_dev_ioctl" to make it work. > LOL, yes, that was a dumb mistake. > > I'll send it to Andrew Morton, after some fairly simple sanity testing, > with both our Signed-off-by added. > >> Tomas >> >> >> On 07/02/2018 03:42 AM, Ian Kent wrote: >>> On Mon, 2018-07-02 at 09:10 +0800, Ian Kent wrote: >>>> On Mon, 2018-07-02 at 00:04 +0200, tomas wrote: >>>>> Hi, >>>>> >>>>> I've looked into this issue found by Syzbot and I made a patch: >>>>> >>>>> https://syzkaller.appspot.com/bug?id=d03abd8b42847f7f69b1d1d7f97208ae425 >>>>> b116 >>>>> 3 >>>> Umm ... oops! >>>> >>>> Thanks for looking into this Tomas. >>>> >>>>> The autofs subsystem does not check that the "path" parameter is present >>>>> within the "param" struct passed by the userspace in case the >>>>> AUTOFS_DEV_IOCTL_OPENMOUNT_CMD command is passed. Indeed, it assumes a >>>>> path is always provided (though a path is not always present, as per how >>>>> the struct is defined: >>>>> https://github.com/torvalds/linux/blob/master/include/uapi/linux/auto_de >>>>> v-io >>>>> ct >>>>> l.h#L89). >>>>> Skipping the check provokes an oob read in "strlen", called by >>>>> "getname_kernel", in turn called by the autofs to assess the length of >>>>> the non-existing path. >>>>> >>>>> To solve it, modify the "validate_dev_ioctl" function to check also that >>>>> a path has been provided if the command is >>>>> AUTOFS_DEV_IOCTL_OPENMOUNT_CMD. >>>>> >>>>> >>>>> --- b/fs/autofs/dev-ioctl.c 2018-07-01 23:10:16.059728621 +0200around >>>>> +++ a/fs/autofs/dev-ioctl.c 2018-07-01 23:10:24.311792133 +0200 >>>>> @@ -136,6 +136,9 @@ static int validate_dev_ioctl(int cmd, s >>>>> goto out; >>>>> } >>>>> } >>>>> + /* AUTOFS_DEV_IOCTL_OPENMOUNT_CMD without path */ >>>>> + else if(_IOC_NR(cmd) == AUTOFS_DEV_IOCTL_OPENMOUNT_CMD) >>>>> + return -EINVAL; >>>> My preference is to put the comment inside the else but ... >>>> >>>> There's another question, should the check be done in >>>> autofs_dev_ioctl_openmount() in the same way it's checked in other >>>> ioctls that need a path, such as in autofs_dev_ioctl_requester() >>>> and autofs_dev_ioctl_ismountpoint()? >>>> >>>> For consistency I'd say it should. >>>> >>>>> >>>>> err = 0;You should just put the "_IOC_NR" directive around "cmd" in >>>>> the lines added to "validate_dev_ioctl" to make it work. >>>>> out: >>>>> >>>>> >>>>> Tested and solves the issue on Linus' main git tree. >>>>> >>>>> >>> Or perhaps this (not even compile tested) patch would be better? >>> >>> autofs - fix slab out of bounds read in getname_kernel() >>> >>> From: Ian Kent >>> >>> The autofs subsystem does not check that the "path" parameter is >>> present for all cases where it is required when it is passed in >>> via the "param" struct. >>> >>> In particular it isn't checked for the AUTOFS_DEV_IOCTL_OPENMOUNT_CMD >>> ioctl command. >>> >>> To solve it, modify validate_dev_ioctl() function to check that a >>> path has been provided for ioctl commands that require it. >>> --- >>> fs/autofs/dev-ioctl.c | 15 +++++++-------- >>> 1 file changed, 7 insertions(+), 8 deletions(-) >>> >>> diff --git a/fs/autofs/dev-ioctl.c b/fs/autofs/dev-ioctl.c >>> index ea4ca1445ab7..61c63715c3fb 100644 >>> --- a/fs/autofs/dev-ioctl.c >>> +++ b/fs/autofs/dev-ioctl.c >>> @@ -135,6 +135,11 @@ static int validate_dev_ioctl(int cmd, struct >>> autofs_dev_ioctl *param) >>> cmd); >>> goto out; >>> } >>> + } else if (cmd == AUTOFS_DEV_IOCTL_OPENMOUNT_CMD || >>> + cmd == AUTOFS_DEV_IOCTL_REQUESTER_CMD || >>> + cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD) { >>> + err = -EINVAL; >>> + goto out; >>> } >>> >>> err = 0; >>> @@ -433,10 +438,7 @@ static int autofs_dev_ioctl_requester(struct file *fp, >>> dev_t devid; >>> int err = -ENOENT; >>> >>> - if (param->size <= AUTOFS_DEV_IOCTL_SIZE) { >>> - err = -EINVAL; >>> - goto out; >>> - } >>> + /* param->path has already been checked */ >>> >>> devid = sbi->sb->s_dev; >>> >>> @@ -521,10 +523,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file >>> *fp, >>> unsigned int devid, magic; >>> int err = -ENOENT; >>> >>> - if (param->size <= AUTOFS_DEV_IOCTL_SIZE) { >>> - err = -EINVAL; >>> - goto out; >>> - } >>> + /* param->path has already been checked */ >>> >>> name = param->path; >>> type = param->ismountpoint.in.type; >>