Yes, it is completely legal to edit the Linux kernel since it is under General Public License - GNU. Linux kernel is an open-source project; it encourages people to edit, fix, and report.