From patchwork Fri Dec 30 11:00:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 37642 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2838375wrt; Fri, 30 Dec 2022 03:10:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXsBQu07xErMMsHivPeiOBscpMvwakSl4INevEho2WIoIxYbmrzMH748fCDXAJlMcVC3OKZG X-Received: by 2002:a17:906:309a:b0:819:7d8f:9684 with SMTP id 26-20020a170906309a00b008197d8f9684mr30611180ejv.72.1672398603599; Fri, 30 Dec 2022 03:10:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672398603; cv=none; d=google.com; s=arc-20160816; b=iallS1bMD8LuuYPdMTvbEAUfCTf+kRE9ibke32kvUXUii+jWLLhP+BSOz+7Won2xNe mUdae8mbudlWMEG4k8n91M1QjVtt/0KCBpc7/xuKIT82q4zspKi2wnEcXypPNKzEPqyB 0kRjVhRwZLwkEbiw5WiNN9zHFDAG0/7f6bgRhER+7HQ5oHpN0yvC0wS/yLpRNJgXSY/w n0hxNY9aAE9P8jJoN78JHp3vMXrt53SrvcKbq1IOyqoGseFtEjs7Z6vC1uShSqUfgT7P 0xb+NHWBn/tp5TVKAn1hU0UVXuqkJykfdcMqK7xi7CvnKu4fZNQrjT2lqvJlHLArKXyz qERg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=lxndJAPqkkg+7Ix0bR4//3QWQHh62xysWAMqysIRogg=; b=t+Bxp1ic21X27rzzfeE6uR3NDI+nk9TTvgxQW3LAZP/iov4iWh+XMRuJwjgshhmQwv 2DLU6iNkq42TTiaW2UuG1hYn8qkHJtlu7L4wcE0JvpSmIKk66Y6BfLh/QfvN3j47BUVk kIbyp/0eOykfl/WEtF9BFAmbg95a2kqCOz+TYI69/9PxMKc3UYtRbUX9VeyfRIoLOleJ JSB65Qmg7x6h1WHY6vwPwrBvVLmJB8w+DlZWH0VHubQHamQa3LDzWqKv3i+BGBDE0/4d AqykUXBxX6dqkYjxXuBdGwc/ImEJMxqZn0jwLzVe5qWZBrxWY7990vVi1Z5wvHtHrdjB sqqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r4S60t+e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t13-20020a170906178d00b007c19ace9799si14935926eje.952.2022.12.30.03.09.37; Fri, 30 Dec 2022 03:10:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r4S60t+e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230056AbiL3LAA (ORCPT + 99 others); Fri, 30 Dec 2022 06:00:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbiL3K77 (ORCPT ); Fri, 30 Dec 2022 05:59:59 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA1F91A3A6 for ; Fri, 30 Dec 2022 02:59:57 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id j8-20020a17090a3e0800b00225fdd5007fso11765154pjc.2 for ; Fri, 30 Dec 2022 02:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lxndJAPqkkg+7Ix0bR4//3QWQHh62xysWAMqysIRogg=; b=r4S60t+e7LHJD84L4tGRkRjswj8B2srCvk7wIaOyMdPLpuAdJNk8govJKTrz9UGKWY 6KrXE+RfpY0E6kdX3zBmuzZ5azWaJgfoPXkJKWigg4TFrHazZY3XhpcpOWQYnZI+LV0a YQ8OvN1X8JqLkpQe91eTg+5oppyBOZC9FAj8/py/ZIhF1hlqun4ml3iAXZxH3XbY8Db2 7QKJjfXwYujAw9z6rq7fkPIkIvj2jnaXcs6o9B8nefySlMDw+8CdmX16/cIdQ4tNgIul 0vyfbrd8dqA/JlOP+Jla3JjoKvIbOzaCsChJHAvz/WE3fW/EsMnhx2eyOh+B84Xx6XeH 34bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lxndJAPqkkg+7Ix0bR4//3QWQHh62xysWAMqysIRogg=; b=TRTN7D2OWgpk+zrvMXufwWxHSf2FfgELaOHFBWFrV1jjn88XEaEEngA7MdO5AXMgD4 339kEYYKsoLyR8l38DhlPR3wxI9hzkPw9INj4LoDADdPhV18e3Oi99lNqFzu8MVhVAyh tqFQpRw616q5WaAGLn21RsG4d5fOpC5yi5gg8BNAWXJKMDyeSunXdHVDDlnll0x1d+WS FzuAw6Oe5Ay5Vn4aUA8m7qv5EL5jKlhfY1ja2elmWunE0dhcWZZ/xO8EKlT6GNi7jdLi 7LCoQHO3jU74DkVJCOq9v2JQ7DjMulqf/n72Jb0jrXeR4jNsWDwo33Zfh0ftPk5eXrFk Nu+Q== X-Gm-Message-State: AFqh2kpYZ5ofpktA4aikgYbC003J06Rv+vqnQLxs1ejd+GU2xRfosbMz aydNnZHTuAeGWEyLqdRQhYTldA== X-Received: by 2002:a17:902:cec2:b0:185:441e:6ef3 with SMTP id d2-20020a170902cec200b00185441e6ef3mr54743349plg.61.1672397997228; Fri, 30 Dec 2022 02:59:57 -0800 (PST) Received: from niej-dt-7B47.. (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id n6-20020a170903110600b00186a437f4d7sm14662525plh.147.2022.12.30.02.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Dec 2022 02:59:56 -0800 (PST) From: Jun Nie To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tudor.ambarus@linaro.org Subject: [PATCH 1/2] ext4: optimize ea_inode block expansion Date: Fri, 30 Dec 2022 19:00:15 +0800 Message-Id: <20221230110016.476621-1-jun.nie@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753637037831999493?= X-GMAIL-MSGID: =?utf-8?q?1753637037831999493?= Copy ea data from inode entry when expanding ea block if possible. Then remove the ea entry if expansion success. Thus memcpy to a temporary buffer may be avoided. If the expansion fails, we do not need to recovery the removed ea entry neither in this way. Signed-off-by: Jun Nie --- fs/ext4/xattr.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 7decaaf27e82..235a517d9c17 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -2551,9 +2551,8 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode, is = kzalloc(sizeof(struct ext4_xattr_ibody_find), GFP_NOFS); bs = kzalloc(sizeof(struct ext4_xattr_block_find), GFP_NOFS); - buffer = kvmalloc(value_size, GFP_NOFS); b_entry_name = kmalloc(entry->e_name_len + 1, GFP_NOFS); - if (!is || !bs || !buffer || !b_entry_name) { + if (!is || !bs || !b_entry_name) { error = -ENOMEM; goto out; } @@ -2565,12 +2564,18 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode, /* Save the entry name and the entry value */ if (entry->e_value_inum) { + buffer = kvmalloc(value_size, GFP_NOFS); + if (!buffer) { + error = -ENOMEM; + goto out; + } + error = ext4_xattr_inode_get(inode, entry, buffer, value_size); if (error) goto out; } else { size_t value_offs = le16_to_cpu(entry->e_value_offs); - memcpy(buffer, (void *)IFIRST(header) + value_offs, value_size); + buffer = (void *)IFIRST(header) + value_offs; } memcpy(b_entry_name, entry->e_name, entry->e_name_len); @@ -2585,25 +2590,26 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode, if (error) goto out; - /* Remove the chosen entry from the inode */ - error = ext4_xattr_ibody_set(handle, inode, &i, is); - if (error) - goto out; - i.value = buffer; i.value_len = value_size; error = ext4_xattr_block_find(inode, &i, bs); if (error) goto out; - /* Add entry which was removed from the inode into the block */ + /* Move ea entry from the inode into the block */ error = ext4_xattr_block_set(handle, inode, &i, bs); if (error) goto out; - error = 0; + + /* Remove the chosen entry from the inode */ + i.value = NULL; + i.value_len = 0; + error = ext4_xattr_ibody_set(handle, inode, &i, is); + out: kfree(b_entry_name); - kvfree(buffer); + if (entry->e_value_inum && buffer) + kvfree(buffer); if (is) brelse(is->iloc.bh); if (bs) From patchwork Fri Dec 30 11:00:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 37643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2842192wrt; Fri, 30 Dec 2022 03:20:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXu48f1pYA+LuiHaZR1Si/Tj1P34iW6KDK3bRmWs5Ve1mRxow3ZYTQyeHJlAizzhTsPrCDVg X-Received: by 2002:a17:902:6b89:b0:18f:6cb:1730 with SMTP id p9-20020a1709026b8900b0018f06cb1730mr31753165plk.26.1672399226864; Fri, 30 Dec 2022 03:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672399226; cv=none; d=google.com; s=arc-20160816; b=eWB5Xoq8GL+ebvqJ6/8HVSndlA80VGJSfSI5ajqBS7avllG8g41tbyQMz2pKWvg8jk JlxapKauhVASr1oztE90rYXBMJBdtTMA0ZCP15ZuTWupkYQklZlZYSCe2lILxFNqq4B3 q25DtVnY7fgJ8jAv1DtV1radTDgN5iae2d0YGVIboPiagg3NF87js26eD3bJ14hzcEi/ fJkoEd34MDyceYhP4XzzaGwva6Mo4SuhB7d3C5QrSWkJlLBnXHgQMIAUsbys/AXIxsJa eB2uVYIaFSvMkQScTbCaDliirpdzPzTfELq862w2Uf2SGVJN/yrAC4cweau5r+9L5xmq L5vw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ahkStRU6mZ/j+Lj49hs0SrtIZtOi4h+JM4lKoZJx6Y0=; b=K9L4+quAhhRYjcW2irSpjjTcOM4HOnlGUEMlZNC73zzTotjFoN++NFfnz5m2C1FekI WX1MJ4QQnfwJT7p439iONT25rnuwNxjTGgmeiAhF8Cdq6Z5Oyuw/f+sBqeWxCjU2PoBQ 8wU7A2KmMNj3MaOlVOYchEgr2gVXLHVRq8ohs/99xdeb1kzRhBLoa96+zb/3AVfjZdh1 iETlru8guid54tUNTkpzLKFazkM4OwSyDFm4/cXPyEBpPS4whHsFTahyOPhx9QzJLPNR Ci/lHJlSmMlcdka6C7EeK6lFIxoiH3okq+dUdLZK7NdApKfF3zoRW9LB3qBRpWNEFQSl Z11Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e3HEINbn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a170902f2cb00b0017f77922b11si19597175plc.84.2022.12.30.03.20.14; Fri, 30 Dec 2022 03:20:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e3HEINbn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbiL3LAG (ORCPT + 99 others); Fri, 30 Dec 2022 06:00:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234376AbiL3LAD (ORCPT ); Fri, 30 Dec 2022 06:00:03 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 404D71A819 for ; Fri, 30 Dec 2022 03:00:02 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so25477704pjj.2 for ; Fri, 30 Dec 2022 03:00:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ahkStRU6mZ/j+Lj49hs0SrtIZtOi4h+JM4lKoZJx6Y0=; b=e3HEINbnqThpfVCwEBmANE9t6wazfU0CqSlTPViHpaoGjovSAYUApwjFm3t8bmC8l6 msnEcLQsf9yJERT6yLriiVMPvG/rqyHdhMf7Oc4EVeTnLUlny2erObvsxbvgWLc94I0I Hfp398jakVZquSf0v2Q9BHn1P6pKwBQHP5I/dLz8yzRL9RQxcpX34Zxq9OvNceDdZeyw SzgJQgzUYuE2KS+7/VcVwbRdxLh6rmG4s8b1YGed1CLJSkOoRtVcy4imn6UJsTICbBWQ /pEPtUxYaFybK7GN6cWXHifeJEDCzReTOMtohU/fvz18qaMAUIZZH5Gnwn+xEAQ/wB/2 eufg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ahkStRU6mZ/j+Lj49hs0SrtIZtOi4h+JM4lKoZJx6Y0=; b=QeC3Z7W+1wmfrhSyvR3yRg3BPQKbjIAQY1/a+Qxtu3rs3PbHjMnUb5/DCnlnZivrZ5 0HkezCnyH/Esduwc5eHzTTLmspj/Lkhty4SSHfpd03edM33BqclZ/fcrAmsWS1VNSTFr /+hdQxe5NcMrw5OFny0vd9qddOrnQtA+FS2vazGhpYmIv4QnNz4Jvr5j6Cgz3JDlwD/F H5dC/Vz3fONrM3EJRqQaVlWgYqDIdfJwM2u6uU+V+lDW7io2vmCxWmtjatEg5hCCXZeI ENWdl8KS/LpA7C7TXp2WJevvCdWI/BACLrOFKRleckMAjU6AAUEEESfH9jWUM701Snmc RqJA== X-Gm-Message-State: AFqh2koXu+spRc48TZ4bJ69wejT7IOV/FSXWsTRHApM2Fa8tayeR0joy Jo7Fs0VMqHEmlSusrWrV7+aRUA== X-Received: by 2002:a17:902:848d:b0:189:5f5c:da1d with SMTP id c13-20020a170902848d00b001895f5cda1dmr31017474plo.18.1672398001764; Fri, 30 Dec 2022 03:00:01 -0800 (PST) Received: from niej-dt-7B47.. (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id n6-20020a170903110600b00186a437f4d7sm14662525plh.147.2022.12.30.02.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Dec 2022 03:00:01 -0800 (PST) From: Jun Nie To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tudor.ambarus@linaro.org Subject: [PATCH 2/2] ext4: refuse to create ea block when umounted Date: Fri, 30 Dec 2022 19:00:16 +0800 Message-Id: <20221230110016.476621-2-jun.nie@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221230110016.476621-1-jun.nie@linaro.org> References: <20221230110016.476621-1-jun.nie@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753637691193650615?= X-GMAIL-MSGID: =?utf-8?q?1753637691193650615?= The ea block expansion need to access s_root while it is already set as NULL when umount is triggered. Refuse this request to avoid panic. Reported-by: syzbot+2dacb8f015bf1420155f@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=3613786cb88c93aa1c6a279b1df6a7b201347d08 Signed-off-by: Jun Nie --- fs/ext4/xattr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 235a517d9c17..ac58494e49b6 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1422,6 +1422,12 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle, uid_t owner[2] = { i_uid_read(inode), i_gid_read(inode) }; int err; + if (inode->i_sb->s_root == NULL) { + ext4_error(inode->i_sb, + "refuse to create EA inode when umounting"); + return ERR_PTR(-EINVAL); + } + /* * Let the next inode be the goal, so we try and allocate the EA inode * in the same group, or nearby one.