Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp30142pxb; Fri, 15 Jan 2021 05:07:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwx1m/rf9gfdqmD/m5tJj94g9dhTqdZd2TncnYc7EG0AEQucfo9pw+5ooyRrbNNa2iV7HmS X-Received: by 2002:aa7:d999:: with SMTP id u25mr9360883eds.297.1610716066424; Fri, 15 Jan 2021 05:07:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610716066; cv=none; d=google.com; s=arc-20160816; b=FJFKXcGwYanmyltFzIxAl5sLmqnl4/j4Z3O2p3Vg2Wl4DwjWRX7lr0zBwF16wY0PTu lyIqT1YPLEyCEPET/e4hzLEvOex1z1KkHbJudZNSrOLlHHb2wWtG4DKV5If/ZlgqXNKq D53QdC0Lm8qQt7bRs7axyKvNVjP6K1c26bAc/MEpbnWuHn4oo4JGterY0Il8+a23Z+Oo 1G90GKdsXywokpTShca+sA5xc3D5MjaNSI8RUQmlQlMGH1AmoVBA1AZmEl/kfKCitMlS 05t3xjf/2jyW14RuFsVA8+dSR1SC3VTPNw4pYChrydhbwi1QTABTSfBRAEsimYcDy6Mu bNtg== 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=tfXGTjxlFhaM9LOCVAbl07f7TsIM4ag8PtHCOnBgqx4=; b=rnEog7+pUOxZ/Xmbgfrq3YH2aBDJKOV+yT7ag4HSRHvl2Mxv+ZlETYvlgLN7RqI5oY mq25UmgSPUJqdawHWTDMcPOMgarQahREZ7NqnQNkXXwzo+mNYjcF+iSdio8MyCwDetkx GtMs5/UBhVh+X0G9YNFmMnJ+eshGHa4WClFFQmxWGH2REG0FU04utT5KEufI0yzX6sUg +EKubZlXghOCSWPFsjjuE5CbebUkKF71jbkT5t4UcO2YWWlzHqL4/wVc0uDH3ocWbqUA Y7i/3xxQfyc1N+OzICNqqMDmIJKvLoMMHo6PWIR18ciD1ecm8XdVD3szox2Bcxodylhs y/JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Wm/lns3a"; 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 l15si3726423ejk.413.2021.01.15.05.07.20; Fri, 15 Jan 2021 05:07:46 -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="Wm/lns3a"; 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 S2388544AbhAONF7 (ORCPT + 99 others); Fri, 15 Jan 2021 08:05:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:36246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732610AbhAOMb0 (ORCPT ); Fri, 15 Jan 2021 07:31:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DAFCA2333E; Fri, 15 Jan 2021 12:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610713859; bh=C4QXe8+HEIga6AqCcUTyir1PTpQjRJx+AJkHUyp9Hrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wm/lns3aie/0Jq4gGZ13kl9JJ1KYRcVylFIgF+oIBlcIcincpV68ecS8kfm1TxppD 9qEhs6v7Xr9QUXG8ZQNrZkKXMdFPKzWf5KjOfeCQj/vVNxDNZSYGILYE68s5usMBai NTQdYmI0Uckvsr5MLlOAP74Om1fRpaEN+7/o/j78= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Weinberger , Zhihao Cheng , Sudip Mukherjee Subject: [PATCH 4.14 10/28] ubifs: wbuf: Dont leak kernel memory to flash Date: Fri, 15 Jan 2021 13:27:47 +0100 Message-Id: <20210115121957.258514238@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121956.731354372@linuxfoundation.org> References: <20210115121956.731354372@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 [sudip: adjust context] Signed-off-by: Sudip Mukherjee 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 @@ -331,7 +331,7 @@ void ubifs_pad(const struct ubifs_info * { uint32_t crc; - ubifs_assert(pad >= 0 && !(pad & 7)); + ubifs_assert(pad >= 0); if (pad >= UBIFS_PAD_NODE_SZ) { struct ubifs_ch *ch = buf; @@ -727,6 +727,10 @@ int ubifs_wbuf_write_nolock(struct ubifs * write-buffer. */ memcpy(wbuf->buf + wbuf->used, buf, len); + if (aligned_len > len) { + ubifs_assert(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", @@ -819,13 +823,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(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;