Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2794754ybi; Thu, 18 Jul 2019 14:36:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyV7JvOWtVtTyR+Ei23y/7h0Ppf9eZcBWeS/mnjnMyR6NhQrjjCLS+uZuOkfN3uDfz2jIf5 X-Received: by 2002:a17:90a:b011:: with SMTP id x17mr53940726pjq.113.1563485810869; Thu, 18 Jul 2019 14:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563485810; cv=none; d=google.com; s=arc-20160816; b=eZUeizHap9faMnAn8tZtxDY/nTqqL6IxgMLbbtFg3XgrdvmfalTHz2Fm5c963Ma5dj s+pMf5C9jKMKMXDhED6JlatbtrSbFfYKO68XEerVLE6kGVxA5YFjtkXf4ICnZk0+TS9U EjkspeQA+t728hufUffp7WtcMW89ILrnIwecPaK6g1jIamKscm9YzD4dSJr2R50uzC8B MS0kNTJJIvYmHBGwu4p8Ehg4Eh+hfTi2wUxQ39A+TJuc2tjc9B1NYuSvXyCuVpT5m2C+ qRxUorikeGm98SLD4OgI5vdgQYep0v6G7ZbUzqV8w3XpXMEo67Nu8jJReWEEps65IGVt fulg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=KkttYUYXAWuWBOKGYfn41xR+6vj7CFYrcZ8YCFpnCUQ=; b=pIN1pBx2ilDfJSm+oojx0g1htGejqqH2UkknJ08wi+lhzl4KTZ5En3Q9NzgoFA7nlO uRhEJQF5FGLZjAiRu74+n/WlGsuTDxH5BG19SCE4qgkEp29poKo6QEAsIbUIHIyONG2Z 2jwViKBgAgRuXWO86/IgEgxP+SdtuG6nKdHLz1q2eEVQrJxuTaXuSPPF/LuPo030YgAn 5dFYM3CAUydLszYuT3ZRNPIb9uUJKyAhxIb+vL9GDdjgT3cWll8HlrJfeSaej9rhlEiy ruHnT43H7tPH7jukIDMt8YSIH/jiqtl2ohuR3+MfFe/law2d0UxGYl1b0YVP93twrpaK bbsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eKO2yoYF; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18si1834pgf.457.2019.07.18.14.36.35; Thu, 18 Jul 2019 14:36:50 -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=@chromium.org header.s=google header.b=eKO2yoYF; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391534AbfGRVfs (ORCPT + 99 others); Thu, 18 Jul 2019 17:35:48 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37907 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727780AbfGRVfs (ORCPT ); Thu, 18 Jul 2019 17:35:48 -0400 Received: by mail-pf1-f193.google.com with SMTP id y15so13202161pfn.5 for ; Thu, 18 Jul 2019 14:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=KkttYUYXAWuWBOKGYfn41xR+6vj7CFYrcZ8YCFpnCUQ=; b=eKO2yoYFYu3Tnhrp1Rx1k9pfRxTZSm6XeyDXK0qTzarYNq4CcveUMKhrhOO+L5z1eb Xt/N0Fp8730Doh929vOfA27ApjGm1UoMAjfMzvuMUSKbuSekYJHMP0l80bRqM1BUWaK9 Xx3cNZlgKViPwsCWwRg9KpWHaAJnOx4HYCR4g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=KkttYUYXAWuWBOKGYfn41xR+6vj7CFYrcZ8YCFpnCUQ=; b=tXCopVkipdiNGny/B7pUbNGef29389jwd1vuVPL5uTB7Kkpx/IKy4maMFeCGYzZSJt Ic8IAPgO/5FZnFJ4CxD7ZDeCimfHB1IXuw8PfzszcsfVhhPB9mixyrSzP942HiIC9ipX me1jRtr5P6fEOXGyjRJWqVSivJyK6c5Y/mJBQlcetlcj8HNAA4fpzzkTC41w0CYSrBx1 cWyEutydLYJLzOz8w9lMedjJcvZ6E6BhD8yKyG2YbrcqEkgjhjyltP0prtgdHVgITdx/ /igYX4V1ZC4zgVDlCZqPcY6NFjb76saHpyhqUieOhpipQeqPZIDpQRtjSngvyQvX8iiI tg6Q== X-Gm-Message-State: APjAAAWqibsgOgBXSmye79gKJLiVdRbFBoBr6kMJXMbrQj+b+aRBgBRn bJkujBbur4qCsDr5p/fg1FonorC3VD4= X-Received: by 2002:a63:3fc9:: with SMTP id m192mr50998872pga.429.1563485747382; Thu, 18 Jul 2019 14:35:47 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i9sm23169608pjj.2.2019.07.18.14.35.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Jul 2019 14:35:46 -0700 (PDT) Date: Thu, 18 Jul 2019 14:35:45 -0700 From: Kees Cook To: Nick Desaulniers Cc: Jeffrin Thalakkottoor , Steven Rostedt , Andy Shevchenko , Alexander Shishkin , tobin@kernel.org, lkml , Dmitry Vyukov , Alexander Potapenko Subject: Re: BUG: KASAN: global-out-of-bounds in ata_exec_internal_sg+0x50f/0xc70 Message-ID: <201907181423.E808958@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 16, 2019 at 11:28:29AM -0700, Nick Desaulniers wrote: > On Wed, Jul 10, 2019 at 10:44 AM Jeffrin Thalakkottoor > wrote: > > > > hello all , > > > > i encountered a KASAN bug related . here are some related information... > > > > > > -------------------x-----------------------------x------------------ > > [ 30.037312] BUG: KASAN: global-out-of-bounds in > > ata_exec_internal_sg+0x50f/0xc70 > > [ 30.037447] Read of size 16 at addr ffffffff91f41f80 by task scsi_eh_1/149 > > > > > > [ 30.039935] The buggy address belongs to the variable: > > [ 30.040059] cdb.48319+0x0/0x40 > > (gdb) l *ata_exec_internal_sg+0x50f > > 0xffffffff81c7b59f is in ata_exec_internal_sg (./include/linux/string.h:359). > > So looks like ata_exec_internal_sg() is panic'ing when... > > > 354 if (q_size < size) > > 355 __read_overflow2(); > > 356 } > > 357 if (p_size < size || q_size < size) > > 358 fortify_panic(__func__); > > 359 return __builtin_memcpy(p, q, size); ^^^ here, so within memcpy(), but after the "easy" sanity checks. The only place where I see ata_exec_internal_sg() calling memcpy() is here: /* prepare & issue qc */ qc->tf = *tf; if (cdb) memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); the "16" is consistent with the report: include/linux/ata.h: ATAPI_CDB_LEN = 16, which matches the claim about the cdb variable from KASAN. And it's a read, so "cdb" is wrong. Do you have a longer back trace? What called ata_exec_internal_sg()? ata_exec_internal() is the only caller of ata_exec_internal_sg(). Nearly all callers of ata_exec_internal() pass a NULL cdb. Those that don't are: atapi_eh_tur() u8 cdb[ATAPI_CDB_LEN] = ... atapi_eh_request_sense() u8 cdb[ATAPI_CDB_LEN] = ... These two are on the static and correctly sized. eject_tray() static const char cdb[ATAPI_CDB_LEN] = ... zpodd_get_mech_type() static const char cdb[] = ... These are both in rodata, and only the first is correctly sized. I assume the following will fix it: diff --git a/drivers/ata/libata-zpodd.c b/drivers/ata/libata-zpodd.c index 173e6f2dd9af..eefda51f97d3 100644 --- a/drivers/ata/libata-zpodd.c +++ b/drivers/ata/libata-zpodd.c @@ -56,7 +56,7 @@ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev) unsigned int ret; struct rm_feature_desc *desc; struct ata_taskfile tf; - static const char cdb[] = { GPCMD_GET_CONFIGURATION, + static const char cdb[ATAPI_CDB_LEN] = { GPCMD_GET_CONFIGURATION, 2, /* only 1 feature descriptor requested */ 0, 3, /* 3, removable medium feature */ 0, 0, 0,/* reserved */ -- Kees Cook