Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'netconsole-configfs-store-callback-fixes'

Breno Leitao says:

====================
netconsole: configfs store callback fixes

There are still some changes I want to make, such as, having the dynamic
lock when reading from configfs (_show() callbacks), wich will solve
other issues, but I will keep it for later.
====================

Link: https://patch.msgid.link/20260427-netconsole_ai_fixes-v2-0-59965f29d9cc@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+30 -19
+30 -19
drivers/net/netconsole.c
··· 752 752 unregister_netcons_consoles(); 753 753 } 754 754 755 - ret = strnlen(buf, count); 755 + ret = count; 756 756 /* Deferred cleanup */ 757 757 netconsole_process_cleanups(); 758 758 out_unlock: ··· 781 781 782 782 nt->release = release; 783 783 784 - ret = strnlen(buf, count); 784 + ret = count; 785 785 out_unlock: 786 786 dynamic_netconsole_mutex_unlock(); 787 787 return ret; ··· 807 807 goto out_unlock; 808 808 809 809 nt->extended = extended; 810 - ret = strnlen(buf, count); 810 + ret = count; 811 811 out_unlock: 812 812 dynamic_netconsole_mutex_unlock(); 813 813 return ret; ··· 817 817 size_t count) 818 818 { 819 819 struct netconsole_target *nt = to_target(item); 820 + size_t len = count; 821 + 822 + /* Account for a trailing newline appended by tools like echo */ 823 + if (len && buf[len - 1] == '\n') 824 + len--; 825 + if (len >= IFNAMSIZ) 826 + return -ENAMETOOLONG; 820 827 821 828 dynamic_netconsole_mutex_lock(); 822 829 if (nt->state == STATE_ENABLED) { ··· 837 830 trim_newline(nt->np.dev_name, IFNAMSIZ); 838 831 839 832 dynamic_netconsole_mutex_unlock(); 840 - return strnlen(buf, count); 833 + return count; 841 834 } 842 835 843 836 static ssize_t local_port_store(struct config_item *item, const char *buf, ··· 856 849 ret = kstrtou16(buf, 10, &nt->np.local_port); 857 850 if (ret < 0) 858 851 goto out_unlock; 859 - ret = strnlen(buf, count); 852 + ret = count; 860 853 out_unlock: 861 854 dynamic_netconsole_mutex_unlock(); 862 855 return ret; ··· 878 871 ret = kstrtou16(buf, 10, &nt->np.remote_port); 879 872 if (ret < 0) 880 873 goto out_unlock; 881 - ret = strnlen(buf, count); 874 + ret = count; 882 875 out_unlock: 883 876 dynamic_netconsole_mutex_unlock(); 884 877 return ret; ··· 903 896 goto out_unlock; 904 897 nt->np.ipv6 = !!ipv6; 905 898 906 - ret = strnlen(buf, count); 899 + ret = count; 907 900 out_unlock: 908 901 dynamic_netconsole_mutex_unlock(); 909 902 return ret; ··· 928 921 goto out_unlock; 929 922 nt->np.ipv6 = !!ipv6; 930 923 931 - ret = strnlen(buf, count); 924 + ret = count; 932 925 out_unlock: 933 926 dynamic_netconsole_mutex_unlock(); 934 927 return ret; ··· 964 957 goto out_unlock; 965 958 memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN); 966 959 967 - ret = strnlen(buf, count); 960 + ret = count; 968 961 out_unlock: 969 962 dynamic_netconsole_mutex_unlock(); 970 963 return ret; ··· 1079 1072 size_t count) 1080 1073 { 1081 1074 struct userdatum *udm = to_userdatum(item); 1075 + char old_value[MAX_EXTRADATA_VALUE_LEN]; 1082 1076 struct netconsole_target *nt; 1083 1077 struct userdata *ud; 1084 1078 ssize_t ret; 1085 1079 1086 - if (count > MAX_EXTRADATA_VALUE_LEN) 1080 + if (count >= MAX_EXTRADATA_VALUE_LEN) 1087 1081 return -EMSGSIZE; 1088 1082 1089 1083 mutex_lock(&netconsole_subsys.su_mutex); 1090 1084 dynamic_netconsole_mutex_lock(); 1091 - 1092 - ret = strscpy(udm->value, buf, sizeof(udm->value)); 1093 - if (ret < 0) 1094 - goto out_unlock; 1085 + /* Snapshot for rollback if update_userdata() fails below */ 1086 + strscpy(old_value, udm->value, sizeof(old_value)); 1087 + /* count is bounded above, so strscpy() cannot truncate here */ 1088 + strscpy(udm->value, buf, sizeof(udm->value)); 1095 1089 trim_newline(udm->value, sizeof(udm->value)); 1096 1090 1097 1091 ud = to_userdata(item->ci_parent); 1098 1092 nt = userdata_to_target(ud); 1099 1093 ret = update_userdata(nt); 1100 - if (ret < 0) 1094 + if (ret < 0) { 1095 + /* Restore the previous value so it matches the live payload */ 1096 + strscpy(udm->value, old_value, sizeof(udm->value)); 1101 1097 goto out_unlock; 1098 + } 1102 1099 ret = count; 1103 1100 out_unlock: 1104 1101 dynamic_netconsole_mutex_unlock(); ··· 1144 1133 disable_sysdata_feature(nt, SYSDATA_MSGID); 1145 1134 1146 1135 unlock_ok: 1147 - ret = strnlen(buf, count); 1136 + ret = count; 1148 1137 dynamic_netconsole_mutex_unlock(); 1149 1138 mutex_unlock(&netconsole_subsys.su_mutex); 1150 1139 return ret; ··· 1173 1162 disable_sysdata_feature(nt, SYSDATA_RELEASE); 1174 1163 1175 1164 unlock_ok: 1176 - ret = strnlen(buf, count); 1165 + ret = count; 1177 1166 dynamic_netconsole_mutex_unlock(); 1178 1167 mutex_unlock(&netconsole_subsys.su_mutex); 1179 1168 return ret; ··· 1202 1191 disable_sysdata_feature(nt, SYSDATA_TASKNAME); 1203 1192 1204 1193 unlock_ok: 1205 - ret = strnlen(buf, count); 1194 + ret = count; 1206 1195 dynamic_netconsole_mutex_unlock(); 1207 1196 mutex_unlock(&netconsole_subsys.su_mutex); 1208 1197 return ret; ··· 1236 1225 disable_sysdata_feature(nt, SYSDATA_CPU_NR); 1237 1226 1238 1227 unlock_ok: 1239 - ret = strnlen(buf, count); 1228 + ret = count; 1240 1229 dynamic_netconsole_mutex_unlock(); 1241 1230 mutex_unlock(&netconsole_subsys.su_mutex); 1242 1231 return ret;