From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19F7FC43381 for ; Mon, 18 Mar 2019 16:10:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DA80D2087E for ; Mon, 18 Mar 2019 16:10:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726958AbfCRQKI (ORCPT ); Mon, 18 Mar 2019 12:10:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44102 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726897AbfCRQKI (ORCPT ); Mon, 18 Mar 2019 12:10:08 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12ED63082E06 for ; Mon, 18 Mar 2019 16:10:08 +0000 (UTC) Received: from pegasus.maiolino.com (unknown [10.40.205.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 765DD19C78 for ; Mon, 18 Mar 2019 16:10:07 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Subject: [PATCH] fibmap: Reject negative addresses Date: Mon, 18 Mar 2019 17:10:04 +0100 Message-Id: <20190318161004.10743-1-cmaiolino@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 18 Mar 2019 16:10:08 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org FIBMAP receives an integer from userspace which is then implicitly converted into sector_t on ->bmap(). No check is made to ensure userspace didn't send a negative address, which can confuse the ->bmap interface, and return fuzzy addresses. Signed-off-by: Carlos Maiolino --- I am not 100% sure if is there any reason for ->bmap interface to accept negative values, from the top of my mind, I really can't see a reason, if there is a reason why we don't check for negative addresses, I'd be happy to know, otherwise we should reject it. Cheers fs/ioctl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/ioctl.c b/fs/ioctl.c index fef3a6bf7c78..e3a01c43adb4 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -64,6 +64,11 @@ static int ioctl_fibmap(struct file *filp, int __user *p) res = get_user(block, p); if (res) return res; + + /* No reason to query a negative block addr */ + if (block < 0) + return -EINVAL; + res = mapping->a_ops->bmap(mapping, block); return put_user(res, p); } -- 2.20.1