Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9410901pxu; Mon, 28 Dec 2020 15:36:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHC7BwbHFhTxhwGoXdkAFDil2YB0VpgTk2be3oi1N/jEhbRwTFWmbEyBpjPNFQT2Y++rBN X-Received: by 2002:aa7:d494:: with SMTP id b20mr45433943edr.330.1609198590676; Mon, 28 Dec 2020 15:36:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609198590; cv=none; d=google.com; s=arc-20160816; b=BLNxEfcqJjV11D1AT1Y6Qvrt4D9y+UPYuqxR5cTEDeuGa105ciNDXztA9HUpGOlcIN GBSbtLZU52ku7hjBQJfAgLGYRggr32t9QC7phxGyapBbsK3nS7mzB3Bc/2x5C8CIlx3H I6tNt0eOMWwiDc84/+XhljZ4YLmWyfhZa4ZlOq7npx7OZIa8Ldh8s4SH5YLC8eMr2JQA 52N417vAyA2SvTAX0NTRqgTx0uUXuC2c2Jqom6E+M7BkSoTomEIpj3NPrfFVVOkyuiRE zuHiiUM/x2VV/KDhntNkCHNm8jOuSE/Bn7Tslna/B1OGOp6RuWF+7eAaSnCC48BzuwkO s4pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QToOVeww2FYe3u85iU0psfVMBiOJxU9A48We0NqEhj4=; b=0UOYgS4nhQ+hPj3ozo6OCXKBnD3DGfMkjZpU/x6ZtDdzEnK7NfhnOblsnyHvyl0Gzr OlMGGoYiJFNqcsnniuWVZac6NEddWarpwEdVSX/iFd3Gy42SmAReHuJCySBr70lMouwO oCkLbWg3DFFUL/x1rTHUCYk7gtq09k18x2Gv0nMRuHdfZxx8Xnho+s0VXy4N54GmiBma a9Hazo7jmrICCmB0pRnsq2gUzNmn+aRXXbyWTzhgWwxLkUM5VL3SFlXVShzOXQ7GJT0u gdU3WzerOpWD3DN1s00Nu0kpGsoiOJiRZbZFqJ+sHCZUJjU2CbAhhMsr6VN6RVQOuSIz R+IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nnTP3zUe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs12si18955611ejb.87.2020.12.28.15.35.49; Mon, 28 Dec 2020 15:36:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nnTP3zUe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503434AbgL1O3M (ORCPT + 99 others); Mon, 28 Dec 2020 09:29:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:36870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392094AbgL1O3G (ORCPT ); Mon, 28 Dec 2020 09:29:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C1D9520791; Mon, 28 Dec 2020 14:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165705; bh=0mA020p+l0nBuEoHzeLGKy4wgdjQDlB+neXTbKoMuh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnTP3zUe7rNeSA5DFr8ZRXGW9vdtxsKkVFyjOdpN5MUtTjQpi6q6Od6Pm9UUnQ/76 I6x2aziOsvNC3tBtdBOyEWgClWtWnXRz9M16TbXBwMvV5Il/P/XyuaMTA4xeYE2O4b AvsePAciyC7GlpSFYHxeqiYOSsGWDWJpRsIm5YW8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Weinberger , Zhihao Cheng Subject: [PATCH 5.10 626/717] ubifs: wbuf: Dont leak kernel memory to flash Date: Mon, 28 Dec 2020 13:50:24 +0100 Message-Id: <20201228125050.910992367@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Richard Weinberger commit 20f1431160c6b590cdc269a846fc5a448abf5b98 upstream. Write buffers use a kmalloc()'ed buffer, they can leak up to seven bytes of kernel memory to flash if writes are not aligned. So use ubifs_pad() to fill these gaps with padding bytes. This was never a problem while scanning because the scanner logic manually aligns node lengths and skips over these gaps. Cc: Fixes: 1e51764a3c2ac05a2 ("UBIFS: add new flash file system") Signed-off-by: Richard Weinberger Reviewed-by: Zhihao Cheng Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- fs/ubifs/io.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c @@ -319,7 +319,7 @@ void ubifs_pad(const struct ubifs_info * { uint32_t crc; - ubifs_assert(c, pad >= 0 && !(pad & 7)); + ubifs_assert(c, pad >= 0); if (pad >= UBIFS_PAD_NODE_SZ) { struct ubifs_ch *ch = buf; @@ -764,6 +764,10 @@ int ubifs_wbuf_write_nolock(struct ubifs * write-buffer. */ memcpy(wbuf->buf + wbuf->used, buf, len); + if (aligned_len > len) { + ubifs_assert(c, aligned_len - len < 8); + ubifs_pad(c, wbuf->buf + wbuf->used + len, aligned_len - len); + } if (aligned_len == wbuf->avail) { dbg_io("flush jhead %s wbuf to LEB %d:%d", @@ -856,13 +860,18 @@ int ubifs_wbuf_write_nolock(struct ubifs } spin_lock(&wbuf->lock); - if (aligned_len) + if (aligned_len) { /* * And now we have what's left and what does not take whole * max. write unit, so write it to the write-buffer and we are * done. */ memcpy(wbuf->buf, buf + written, len); + if (aligned_len > len) { + ubifs_assert(c, aligned_len - len < 8); + ubifs_pad(c, wbuf->buf + len, aligned_len - len); + } + } if (c->leb_size - wbuf->offs >= c->max_write_size) wbuf->size = c->max_write_size;